Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get current requested item?

vimal11592
Tera Expert

Hi,

Here what I am doing :

I am trying to request the listed from service catalog.On request one incident gets created and gets assigned to the authorized person for approval.Once the person approve the request there is one script attached that calls the requested item table.That request calls the all incident items from the requested table.On every request approval that script runs.I just want to know How to get that requested item that triggers the script.for examle :

Item1 ----> request -----> approval ---->script ----> output == item1

Item2 ----> request -----> approval ---->script ----> output == item2

Here is my script :

var requestedItem = new GlideRecord('sc_req_item');

      requestedItem.addQuery('active', true);

      requestedItem.query();    

      while (requestedItem.next()) {    

  gs.log("name:requestedItem:"+requestedItem.cat_item.name);

      }

             

It returns all the requested item.

can someone please help me.

Thanks,
Vimal

4 REPLIES 4

Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Vimal



The query you are executing has no restriction.


You will loop into all the active requested items.


If you need just one than you need to provide the sys_id of the actual requested item adding a similar line of code



requestedItem.addQuery('sys_id', XXXXX);



Important also to understand from which table you are trying to execute the code.


I hope this will help


Cheers


R0bo


Hi,



Is there any way to get that sys_id using script.I have designed workflow to be execute on sc_req_item table.




Thanks,


Vimal


Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Vimal



If your script is embedded inside a workflow and the workflow is against a requested item than you can access the information of the actual requested items directly using



current.sys_id



So the code seems not necessary.



Cheers


R0bo


Thank You so much.