cancel
Showing results for 
Search instead for 
Did you mean: 
Product Team
Product Team

Javascript snippets on FSA

No matter how configurable a product is, we always wish there was a way to run our "own" custom logic.

Ability to execute custom logic on mobile devices even when offline is a major game changer. This could be used to perform data validations, data manipulations based on business requirements.

ServiceMax will introduce the capability to execute custom JavaScript snippets on the FSA app for data validation, so that validation errors doesn't have to wait till data gets synced to server. Using the APIs provided, you can query data from the local database, perform custom logic, include a custom error message and experience a visual feedback on the UI.

To start with (Phase1), ServiceMax will support this on change event of "DateTime" field, Before / After Save events, Button click events on SFMs. The custom snippets will be configurable on SFM page layout.  Some use-cases this will address are to validate overlapping time / labor entries (See ,   ) , check for duplicate records using custom logic etc.

We plan to extend this ability to perform data manipulations in Phase2.

If you have more use-cases, we'd love to hear them !

Message 1 of 13
12 Replies
Employee
Employee

Re: Javascript snippets on FSA

Archana Krishnan

  1. Can the JS code Snippet for Time Overlap be modified to extend the logic?
  2. What are the objects in scope for the overlap check?
    • ServiceMax Event
    • Salesforce Event
    • Work Details
    • Time Entries
    • Other Custom Objects
  3. Can you share a sample of the JS Snippet Code?
  4. What is the timeline for Phase 1 & Phase 2 ?

Thanks.

Message 2 of 13
Product Team
Product Team

Re: Javascript snippets on FSA

Mourad LOUNAS

1. Yes the logic will be a custom one.  In the snippet, it will be possible to provide the object and fields on which the logic has to be run, conditions (DB query like) under which the snippet should be run, response structures, message to be displayed.

2. The object will be one of the configurable entity in the snippet.

3. I'll update this thread in a week or so with sample snippet

4. Phase1 is 19.1 . Phase2 is likely 19.2

Message 3 of 13
Employee
Employee

Re: Javascript snippets on FSA

Will the snippet give us access to any of the visual component. For eg. hiding a section/fields of the SFM based on the data? If not, is that a plan to change/add visual components of the SFM through JS?

Message 4 of 13
Employee
Employee

Re: Javascript snippets on FSA

Hi,

A use case I would like to be able to do is include field contents within a warning / error message during validation.  e.g. If i have a field called Pre Start Notes and I want to confirm the technician has read them I'd like to show a warning message.  Currently this message reads 'This Work Order has Pre Start Notes, Please confirm you have read them'.  But we would like to show the actual notes within the warning.

Message 5 of 13
Line Chef frank_vanloon
Line Chef

Re: Javascript snippets on FSA

Could you share an example of a JavaScript Snippet that uses the "query data from the local database" API?

I've used ServiceMax Code Snippets (JavaScript) extensively in the past, but never realized you could do this.. I thought we were limited to just the fields in the SFM.

Message 6 of 13
Employee
Employee

Re: Javascript snippets on FSA

Frank VanLoon​ - This is being introduced so you didn't miss out on it yet. I believe it is coming with 19.1.

Message 7 of 13
0 Likes
Highlighted
Pastry Chef mmajerus6
Pastry Chef

Re: Javascript snippets on FSA

Jahnavi Gosula​. FYI.

bio-rad​

Message 8 of 13
0 Likes
Product Team
Product Team

Re: Javascript snippets on FSA

More on the snippets that we will enable in 19.1 for FSA -

Below APIs will be exposed, that you can use in the snippets.

  1. $db - To access data from client database. Typical use case is to query records in client database for any validations.
  2. $sfm_records - To get the header and child records of the current SFM. A use case for this is fetch records in the SFM that the user is on right now, and include them for custom validation.
  3. $env - To get the application name (FSA_MFL, FSA_ANDROID, FSA_IPAD). This could be used to run custom logic for specific FSA platforms.
  4. $event - To get information on how the snippet is invoked
  5. $response- To respond with the status (Success/Error) of the custom logic to the client application. Can contain the custom message to be shown in the application.

Structure of every API, configuration details and a sample snippet will be included in 19.1 documentation. Here is a quick preview.

$db.get(query_object, callback_function(query, response) { } );

Here, "query_object" will have to be provided with information required to build a SQL query like object, fields, filter condition, advanced expression, sort order. This SQL query would eventually be executed on the client DB.

See screenshots for the UI feedback that would come from $response. To proceed further, user will have to correct the data or discard the record itself.

FeedbackonUI_1.jpegFeedbackonUI_Expanded.jpeg

Message 9 of 13
Pastry Chef smusku
Pastry Chef

Re: Javascript snippets on FSA

@archana_krishna  we have issue with look-up field using $event.

 

$event.get(function(rec) {
console.log('in snippet: event response = ', rec.currentRec);
var parsedRec = JSON.parse(rec);

var FSRName = parsedRec.currentRec['SVMXC__Group_Member__c'];

The above code is returning [object Object]. We couldn't get the look-up value selected by user on SFM to validate. We get all other fields like Date, Boolean, Free text can be access through $event but lookup fields. Do you have any fix for it?

Message 10 of 13
0 Likes