Update “Location” field in the Hardware table.

Mercy
Giga Contributor

Hello Everyone,

 

I have a "Install location" reference filed on my catalog item form.So i have to Update “Location” field in the Hardware table based off the asset that appears in the RITM under Asset tab. The location should be pulled from the “Install Location” field on the form.

So A script would run to update location based off what is on the UI Install Location.I should add run script in the workflow so can some one help me with the script.It would be very thankful.

Thanks.

1 ACCEPTED SOLUTION

Mercy
Giga Contributor

Hello,

 

Thanks for the replies i have done this by using script include and called in workflow run script now the issue is resolved thanks.

View solution in original post

5 REPLIES 5

Priya Shekar
Giga Guru

Hi Mercy,

Check the below links for reference,

https://community.servicenow.com/community?id=community_question&sys_id=46ec0f29db9cdbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=f215c36ddbd8dbc01dcaf3231f96...

If my reply has helped you,Kindly click the Helpful button.
If my reply is the answer you were looking for, Kindly click the Accepted Solution button.

Thanks,
Priya

Moy1
Kilo Guru

Try the following script:

var asset = new GlideRecord('alm_asset');
asset.addQuery('request_line',current.sys_id);
asset.query();

while(asset.next()){

  var eachAsset = new GlideRecord(asset.sys_class_name);
  eachAsset.get('asset_tag',asset.asset_tag);
  if(eachAsset.isValidRecord()){
     eachAsset.location = current.variables.<your location variable>; //replace <your location variable> with the name of your location variable
     eachAsset.update();
  }
}

Mercy
Giga Contributor

Hi Moy,

 

Thanks for the reply but somehow its not working as expected still location in asset harware table is not getting updated with the Install location which is on the Catalog item UI.

Whenever i selects Install location on the UI and submits the Request In RITM below I can see the Asset tab that is beside the task approval,Approvals so there i'm selecting the Asset->new i'm selecting new asset tag and submitting.whenever i open the particular assettag in the harwaretable "alm_asst" there is a location filed consist on the form so that location needs to be updated with the Install location which ever selected on  Catalog Ui .

It should be happen from the workflow for that RUN script should run.

 

I have tried the script which you have provided that is returing with no error but at the same time unable to get the result as well.

The result that you are seeking will not fruition. The script that I have provided will work on a run script activity of a workflow when there are existing assets that are related to that RITM (request line). The workflow will not execute if you add a new asset my clicking the 'new' button on the 'Asset' related tab.

For your requirement, you will need to execute a business rule that executes on all the cases that can be related to the request line. Providing you an example below:

table: cmdb_ci

condition: after / insert

condition script: current.sys_class_name =='alm_asset' && sys_class_name ==<insert the class name>

script:

var RITM = new GlideRecord('sc_req_item');
RITM.get(current.request_line);

if(RITM.isValidRecord()){
   current.location = RITM.<name of the variable that contains the location>;
}