Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Populating ServiceNow variable through the Workflow

MuhammadAqS
Tera Contributor

I have a Workflow script, that is assigning values to different variables. Below is that script:

var grReqItem = new GlideRecord('sc_req_item');
    grReqItem.addQuery('request', current.request);
    grReqItem.addQuery('cat_item', sysid);
    grReqItem.orderByDesc('sys_created_on');
    grReqItem.query();

    if (grReqItem.next()) {
        // Reset the parent and summary fields
        grReqItem.parent = ''; // Don't need parent as they are linked via request
        grReqItem.short_description = 'IT New Starter Application Permissions for ' + current.variables.u_first_name + ' ' + current.variables.u_last_name + ' - ' + current.variables.u_start_date.toString();
       
        // Set the non conditional fields first
        grReqItem.variables.u_first_name = current.variables.u_first_name   ;
        grReqItem.variables.u_last_name = current.variables.u_last_name;
        grReqItem.variables.u_job_title = current.variables.u_title;
        grReqItem.variables.u_start_date = current.variables.u_start_date;
        grReqItem.variables.u_additional_it_requirements = current.variables.u_additional_requirements;
        grReqItem.variables.u_location = current.variables.u_location;
        grReqItem.variables.u_manager = current.variables.u_manager;
        grReqItem.variables.u_user_name = current.variables.u_user_name;
        grReqItem.variables.u_email = current.variables.u_email;


I have created a new variable Approval to Hire ID, and I want to assign this value also. I've written the below line but that's not working:

grReqItem.variables.u_approval_to_hire_id = current.variables.u_approval_to_hire_id;


19 REPLIES 19

@MuhammadAqS 

so you have record producer and then you are creating RITM and REQ and copying variable to RITM

variable "u_approval_to_hire_id" in record producer is of what type?

variable "u_approval_to_hire_id" in catalog item is of what type?

Are you able to print the value in log?

current.variables.u_approval_to_hire_id;

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

The variable type is "Single Line Text" in record producer and catalog item. 

And I'm not able to print it's value. It is empty

@MuhammadAqS 

if it's empty then how it will get set in RITM during creation

That's expected behavior.

What's your requirement here if that variable is empty?

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

No, it's empty in the RITM. 

I have entered a value in that variable on the record producer, but it's not populating on the RITM

@MuhammadAqS 

but you said when you printed in logs it gave empty?

share that variable configuration screenshot? is that variable part of some variable set?

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