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

Ankur Bawiskar
Tera Patron
Tera Patron

@MuhammadAqS 

so all the lines are working except this line?

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

If it's a new variable then it won't have value for the older RITM

what's your business requirement here? updating variables for which RITM and from which RITM?

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

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

yes, except this everything is working fine. 

The business requirement is to show these variables in the Variable Editor section on the RITM.

@MuhammadAqS 

but why are you populating it from workflow?

You didn't answer the other question

what's your business requirement here? updating variables for which RITM and from which RITM?

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

It has already set up through the workflow.

And there is a record producer that once submitted, generates an RITM against a REQ. So the variables are setting up through the workflow, that is running behind