Salesforce Field Service API

executeFSLFlow

The executeFSLFlow API will attempt to load the Flow with the specified name or version Id, and presents the user with a native Flow presentation window which can include any number of admin-defined screens and user interaction. Pulsar attempts to support a similar set of Flow features to the Salesforce Field Service Mobile app. Pulsar only supports Flows of type 'Field Service Mobile Flow' and will only sync the currently activated version of each flow. Please note: This feature is only available if Pulsar for Field Service Lightning is enabled for the user. Also, syncing updated flows requires first using the Refresh Settings button on Pulsar's Settings screen to force Pulsar to look for the updated Flow Metadata.

var request = {
	'type' : 'executeFSLFlow',
	'data' : {
		'FlowName'        : 'Sales_Funnel_Flow1', /* (Required if FlowId is blank) The Flow's Salesforce API name */
		'FlowId'          : '30123456789ABCDEFG', /* (Required if FlowName is blank) The Id of the Flow version */
		'ActionLabel'     : 'Pre-sale Form Flow', /* (Optional) A user-friendly name that will display in the Flow Window 
    											  similar to that used when configuring a Field Service Mobile Settings App Extension name */
		 /* The following are expected flow input variables in Field Service Mobile Flows */
		'Id'              : '08p23456789ABCDEFG', /* (Optional) The ID of the record that the flow is launched from. */
		'UserId'          : '00523456789ABCDEFG', /* (Optional, Automatically defaults to Current User Id) The ID of the current user. */
		'ParentId'        : '0WO23456789ABCDEFG', /* (Optional) The record ID of the parent record that the flow is launched from. 
													For example, if a flow is launched from a service appointment, 
													the ParentId is the ID of the parent work order or work order line item. */
	}
};
bridge.sendRequest(request, function(responseData) {
	if ((responseData.type === 'executefslflowResponse')
		&& (responseData.data != null))
	{
		var responseObject = responseData.data;
		/* the response object contains one property:
			"executed" : the execution state of the flow- true if the flow was presented to the user. false otherwise
		*/
		
	} else {
		// handle the API error ...
	}
});
Retrieve Field Service Metadata
getFSLTemplate

The getFSLTemplate request returns Service Report template metadata. This request will only return data if Field Service Sync is enabled. This request has two modes, each returning an "fslTemplateReponse":

  1. With no data parameters, the response data will be a map of Service Report names to Ids.
  2. With one of two optional parameters below, the response data will be a javascript object representing the requested Service Report Template provided by the Salesforce server.
    1. "TemplateId": Service Report Template Id
    2. "TemplateName": Service report Template Name
  3. With both parameters, the "TemplateId" will take precedence.
var request = { 
	"type" : "getfsltemplate",
	"data" : { 
		"TemplateId" : "001234567890123", // optional. the salesforce Id of the template
		"TemplateName" : "ReportTemplate" // optional. the name of the template
	} 
};

bridge.sendRequest(request, function (results) {
	console.log('Javascript got its response: ' + results);
    if (results.type === "fslTemplateResponse")	{
		// use the results.data object
    } else if (results.type == 'error') {
	    errStr = results.data;
	    alert('A problem occurred:\n' + errStr);
    }
});    
Create a Service Report
createServiceReportFromFilePath

The createServiceReportFromFilePath JSAPI call connects a ServiceReport to a parent object in Salesforce. Use the saveAs JSAPI call to generate a document and retrieve a file path. This file path can be used with this method to connect the ServiceReport to an object in your organization. The response to this call will include the Id of the resulting ServiceReport.

Example
var request = {
	"type": "createservicereportfromfilepath",
	"data": {
		"ParentId": "001234567890123", // The Id of the object to which to associate this ServiceReport object
		"FilePath": "/path/to/file.pdf", // The local path to the file, this is returned by the saveAs JSAPI
		"TemplateId": "000234567890123", // The service report template Id that was used to generate this ServiceReport
		"DocumentName": "file.pdf", // The desired file name of the document
		"ContentType": "application/pdf", // The content type of the provided file
	}
};

bridge.sendRequest(request, function (response) {
	console.log('Javascript got a response: ', response);
    if (response.type === "createServiceReportResponse")	{
		console.log('ServiceReport created with Id = ' + response['data']);
    } else if (response.type == 'error') {
	    errStr = response.data;
	    alert('A problem occurred:\n' + errStr);
    }
});

Related pages