Using GlideRecord in Catalog Item workflow

ceraulo
Mega Guru

Hello!

I have a catalog item with a single-text variable called Location. The value that populates this variable is in the Location table. In the workflow, I want to write a script that gets a field value from the Location table. Is this possible using the single-text variable?

I am pretty sure there is a way if the variable is a reference type but unfortunately the original designer of the catalog item used another variable type. 

Please help.

Thank you.

1 ACCEPTED SOLUTION

Sumit Pandey1
Kilo Guru
Kilo Guru

You can still change it to reference variable, but if for some reason you want to keep as single line text only then you can write a script like below, but in this case you have to make sure name is entered properly in the single line text field.

 

var getLocation = new GlideRecord('cmn_location');
getLocation.addQuery('name', current.variables.SINGLELINEVARIABLENAME);
getLocation.query();
if(getLocation.next()){

//do something

}

View solution in original post

3 REPLIES 3

Sumit Pandey1
Kilo Guru
Kilo Guru

You can still change it to reference variable, but if for some reason you want to keep as single line text only then you can write a script like below, but in this case you have to make sure name is entered properly in the single line text field.

 

var getLocation = new GlideRecord('cmn_location');
getLocation.addQuery('name', current.variables.SINGLELINEVARIABLENAME);
getLocation.query();
if(getLocation.next()){

//do something

}

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

the only way is to query cmn_location table with that single line text variable and get the record.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

palanikumar
Giga Sage

Hi,

Are you validating the value entered in this field before form submission? If not you will face issue in the workflow.

I suggest you to convert this variable to Reference. Converting the variable type will not impact the already submitted RITMs. This change will reflect only the new RITMs create after this conversion.

Thank you,

Palani

Thank you,
Palani