The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Copy Item variable to Request field

shane_davis
Tera Expert

I have a workflow on the sc_req_item table and the workflow has a script activity.   In the script activity, I am trying to copy the value of the "short description" variable to the short description field of the parent Request.  

I tried this with no luck.

sc_request.short_description = current.variables.short_description;

All help is appreciated!

1 ACCEPTED SOLUTION

Shane. My bad


Here is the updated script.



  1. //This function will be automatically called when this rule is processed.  
  2. var gr = new GlideRecord('sc_request');  
  3. gr.addQuery('sys_id',current.request);  
  4. gr.query();  
  5. while(gr.next())  
  6.   {  
  7.   gr.short_description = "Is this working?!"; //assuming short_description is the varaible part of catalog item  
  8.   gr.update();  
  9. }


There was error on 2nd line. Try now pls.


View solution in original post

7 REPLIES 7

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Shane,



You should have the script as.


var gr = new GlideRecord('sc_request');


gr.addQuery('request',current.request);


gr.query();


while(gr.next())


{


  gr.short_description = current.variables.short_description; //assuming short_description is the varaible part of catalog item


  gr.update();


}




I hope this answers your question.


Pradeep,



        Thank you for the quick reply.   The workflow is processing the activity, but is not changing the Request short description.   Rather, it is keeping the short description which is the name of the catalog item.   I don't see any issues that are causing it not to work.




My goal is to:


  1. Trigger the 1st workflow off the Request table which verifies that "Short description is Generic IT Request" .....WORKING
  2. After #1 runs, update the Request short description with the Item variable short description....NOT WORKING


I have a business rule that is copying the Item variable short description to the Item short description....WORKING.



Basically, I need my Generic IT Request catalog item to skip the approval state (working by verifying short description of Generic IT Request) and then set the Request short description to what the user enters into the Item variable short description (which I am also copying to the Item short description in the above mentioned business rule)



I also tried to modify the IF activity that's running off the Request table to say if catalog item is Generic IT Request, but it would let me choose that in the drop-down so that's why I am keying off of short description.


Hi Shane,



Thanks for the update. I am assuming that you are running the script on the worklow on table sc_req_item.


Just for testing purpose hardcode the short description and check if script is working fine or not.


Pradeep,



      I tried the script below and it did not work; kept the catalog item name as the short description.   I don't know how to script so I trial and error while putting various pieces together so let me know if this is wrong.



//This function will be automatically called when this rule is processed.


var gr = new GlideRecord('sc_request');


gr.addQuery('request',current.request);


gr.query();


while(gr.next())


  {


  gr.short_description = "Is this working?!"; //assuming short_description is the varaible part of catalog item


  gr.update();


}




Shane