How to get variables value to the associated task

Roshini
Giga Guru

I have a catalog item "asset details" which have "asset" as one variable and once this item gets submitted  RITM is getting generated, and it will be having an associated Hardware asset refresh line. I need the asset selected in the variable by the end user to be automatically populate in the Hardware asset refresh line field "Asset". Can I know how can this be achieved.

1 ACCEPTED SOLUTION

Rajesh Chopade1
Mega Sage

hi @Roshini 

To automatically populate the "Asset" field in the Hardware asset refresh line with the asset selected in the catalog item "asset details," you can use a 'business rule' or a 'workflow'.

 

Business rule:

create new After Insert BR on table 'sc_req_item'

In condition - item  IS  'YOUR_CATALOG_ITEM'

// Get the selected asset from the catalog item variable
var assetSysId = current.variables.asset_variable; // Replace 'asset_variable' with your actual variable name

//  find the associated Hardware asset refresh line
var hardwareAssetLineGR = new GlideRecord('YOUR_HARDWARE_ASSET_REFRESH_LINE_TABLE'); // Replace with the actual table name
hardwareAssetLineGR.addQuery('request_item', current.sys_id); // Assuming this field relates to the RITM
hardwareAssetLineGR.query();

if (hardwareAssetLineGR.next()) {
    // Set the Asset field to the selected asset
    hardwareAssetLineGR.asset = assetSysId; // Replace 'asset' with the actual field name for the asset in the hardware line
    hardwareAssetLineGR.update(); // Save the changes
}

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh

 

View solution in original post

3 REPLIES 3

Rajesh Chopade1
Mega Sage

hi @Roshini 

To automatically populate the "Asset" field in the Hardware asset refresh line with the asset selected in the catalog item "asset details," you can use a 'business rule' or a 'workflow'.

 

Business rule:

create new After Insert BR on table 'sc_req_item'

In condition - item  IS  'YOUR_CATALOG_ITEM'

// Get the selected asset from the catalog item variable
var assetSysId = current.variables.asset_variable; // Replace 'asset_variable' with your actual variable name

//  find the associated Hardware asset refresh line
var hardwareAssetLineGR = new GlideRecord('YOUR_HARDWARE_ASSET_REFRESH_LINE_TABLE'); // Replace with the actual table name
hardwareAssetLineGR.addQuery('request_item', current.sys_id); // Assuming this field relates to the RITM
hardwareAssetLineGR.query();

if (hardwareAssetLineGR.next()) {
    // Set the Asset field to the selected asset
    hardwareAssetLineGR.asset = assetSysId; // Replace 'asset' with the actual field name for the asset in the hardware line
    hardwareAssetLineGR.update(); // Save the changes
}

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh

 

Thank you so much for your reply,
It works fine.
But I have one more scenario which i missed to mention in the question.

Actually my variable "asset" is a list collector, and it will have more than one assets and the hardware asset refresh line tasks are getting created based on the number of assets selected in the list variable by end user, so each hardware asset refresh line task should have different assets.
suppose end user select a and b assets
1st hardware asset refresh task should have a asset
2nd hardware asset refresh task should have b asset

@Rajesh Chopade1 Thank you, i was able to take it up in array with split and do the iteration.