How do I populate a reference field on a custom table from a requested item using Flow?

TEdwards
Mega Sage

I am working on a POC to create a record on a custom table from a request item using a Flow. I am able to create the record, but it is not setting the value of one of the fields. The variable the value should come from is a lookup select box that references the business application table and the field on the custom table also references the business application table. I am not sure what needs to be done to get that value to populate. 

These are the variables:

find_real_file.png

This is the Flow Action:

 

find_real_file.png

This is the Flow:

find_real_file.png

 

This is the function in the script include:

    createAppURL: function(inputArgs) {
        var appURLObj = {};
        appURLObj.u_business_application = inputArgs.business_application;
        var URLGr = new GlideRecord("sn_apm_application_url");
        URLGr.initialize();
        URLGr.setValue('u_environment', inputArgs.environment);
        URLGr.setValue('u_url', inputArgs.url);
        URLGr.setValue('u_business_application', inputArgs.business_application);
   
        if (URLGr.insert())
            return true;
        else
            return false;
    },

 

And this is the result I get:

 

find_real_file.png

Any assistance would be appreciated.

1 ACCEPTED SOLUTION

Thank you, Rohila.

I was able to accomplish what I wanted by adding a glide record to the script include:

createAppURL: function(inputArgs) {
		var baSysId= '';
        var baGr = new GlideRecord("cmdb_ci_business_app");
		baGr.addQuery('name', inputArgs.business_application);
		baGr.query();
		if(baGr.next()){
		baSysId = baGr.sys_id;
		}
        var URLGr = new GlideRecord("sn_apm_application_url");
        URLGr.initialize();
        URLGr.setValue('u_environment', inputArgs.environment);
        URLGr.setValue('u_url', inputArgs.url);
        URLGr.setValue('u_business_application', baSysId);

        if (URLGr.insert())
            return true;
        else
            return false;
    },

View solution in original post

3 REPLIES 3

Voona Rohila
Tera Patron

Hi Tedwards

the variable is a lookup select box and you are mappint it to refernce field.

can you share how you've configured the variable.

the variable should have 'lookup value field' set to sys_id so that value for the choice will be stored as sysid and you can map it while accessing.

find_real_file.png

or

you need to query the table and get the record matching record with the variable value selected

https://community.servicenow.com/community?id=community_article&sys_id=06c72989db8efc10e2adc22305961...

Thank you, Rohila.

I was able to accomplish what I wanted by adding a glide record to the script include:

createAppURL: function(inputArgs) {
		var baSysId= '';
        var baGr = new GlideRecord("cmdb_ci_business_app");
		baGr.addQuery('name', inputArgs.business_application);
		baGr.query();
		if(baGr.next()){
		baSysId = baGr.sys_id;
		}
        var URLGr = new GlideRecord("sn_apm_application_url");
        URLGr.initialize();
        URLGr.setValue('u_environment', inputArgs.environment);
        URLGr.setValue('u_url', inputArgs.url);
        URLGr.setValue('u_business_application', baSysId);

        if (URLGr.insert())
            return true;
        else
            return false;
    },

Hi Ted

Did my reply answer your question? If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.