how to trigger a flow from a script include and pass parameter which will serve as inputs to Flow/FA

geet
Tera Guru

Hi All,

I have a requirement where on change of requested_for on cat item, I want t to gather the email of the user and then pass that email as an input parameter to the flow action.
For this I have written a Script Include as follows:

var STDMCatalogAPIUTILS = Class.create();
STDMCatalogAPIUTILS.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	
	STDMGetCatalogAPIGetRequestedForDetails: function(){
		
		
		var user = this.getParameter('sysparm_user');
		var UserPropertValue = gs.getProperty('x_stdm_access_mgmt.user_lookup_attribute');
		var email;
		
		var getUser = new GlideRecord("sys_user");
		if (getUser.get(user)) {
			email = getUser.getValue('email');
		}
		return email;
	
		
	},
	
    type: 'STDMCatalogAPIUTILS'
});

On change client-script as follows:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    if (newValue == '')
        g_form.clearValue('select_resource_to_request_access');

    //Type appropriate comment here, and begin script below

    var user = g_form.getValue('requested_for');
    alert(user);

    if (oldValue != newValue) {
        var ga = new GlideAjax('STDMCatalogAPIUTILS');
        ga.addParam('sysparm_name', 'STDMGetCatalogAPIGetRequestedForDetails');
        ga.addParam('sysparm_user', newValue);
        ga.getXMLAnswer(function(answer) {
            if (answer != '') {
                alert("Your Requested For email is  " + answer); // this gives you the property value
            }

        });
    }
}

My next requirement is to pass the email value to the FLOW ACTION input "User Lookup" as follows:

geet_0-1697143261895.png

Once, it gets the email in the input it should trigger this flow action via script and then it will get the response from the REST API call done in flow action step 1.
Once I get the response I want to copy the whole response on the catalog item variable.

Kindly guide me how this is possible, Please.

1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@geet Use the following steps to generate code snippet from an existing flow.

 

Screenshot 2023-10-13 at 8.27.32 AM.pngScreenshot 2023-10-13 at 8.27.51 AM.pngScreenshot 2023-10-13 at 8.56.14 AM.png

Copy the code snippet and paste it inside your script include, set the input parameters. The flow will trigger whenever the method in script include is called.

Hope this helps.