- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2016 09:30 PM
Can someone help me an idea on how to trigger a record update in workflow?
I have a catalog with asset record fields, when this catalog item filled in and submitted approval workflow should trigger and after approved it should capture the changes from the catalog item fields and update the asset record?
Any suggestion on how can we achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2016 10:04 PM
I am not sure, whether there is an more easier way to know any of the "Properties" are updated or not, since you are comparing with another object. In fact, If there are no changes in fields, SNOW GlideRecord will not "Update" actually, though we call "update" function. Here is some sample code to do this.
In "Run script" component, you can write like below.
var updateRequired = false;
var variable1 = current.variable_pool.variable1;
var variable2 = current.variable_pool.variable2;
var assetid = current.variable_pool.assetid;
var grAsset = new GlideRecord('asset table');
if(grAsset.get(assetid))
{
var actualdata1 = grAsset.field1;
var actualdata2 = grAsset.field2;
if(actualdata1 != variable1 || actualdata2 != variable2)
updateRequired = true;
if(updateRequired == true)
{
grAsset.field1 = variable1;
grAsset.field2 = variable2;
grAsset.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2016 10:12 PM
If you want to create a new record, this is the script
var gr= new GlideRecord("alm_asset");
gr.initialize();
gr.model_number=current.variables.<model number variable_name>;
gr.name=current.variables.<model name variable name>;
gr.manufacturer=current.variables.<manufacturer variable name>;
gr.owner=current.variables.<owner variable name>;
gr.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2016 10:18 PM
Thanks Ram and Abhi for helping me on this. I will try with your suggestions.
Just a clarification, It seems there are default workflow running on the system for e.g. service catalog request and service catalog item request, whenever i create a workflow on request, these default workflow is also triggering. I can Inactive the default workflow BUT is there any other way to stop triggering this default workflow?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2016 10:21 PM
Check the conditions on those workflows. I believe right now they do not have any conditions on them. Put conditions so that they will be triggered whenever those conditions are satisfied.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2016 10:28 PM
You can specify "Order" for your workflow lesser than that of default workflow "Service catalog request". Along with the order also specify another property "If condition matches" for default workflow to "Run if no other workflows matched yet"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2016 01:15 AM
Hi Ram,
Thanks Ram, it looks fine i created workflow and things are working as expected.
Only one thing is that is there anyway we can compare set of field values taken into an array with existing field values in the table?
for eg: In the workflow i added the below script which is comparing the model name and Model no alone here likewise Is it possible to have an array which contains set of all variable values into an array and compared to the existing field values in the table? this is because we have to compare each and every variable value with the existing field value, if there is any difference then we have to update it. I understand that now if there is no value changed in variable then the field value remains same BUT what about when we want to remove /clear the value?
And also the line // grModel.name = mod_name_ref; , If i add this then existing field value changed to sysid value not the display value.
var updateRequired = false;
var mod_name_ref = current.variable_pool.add_model_name_ref;
var add_manufact = current.variable_pool.add_manufacturer;
var add_short_desc = current.variable_pool.add_short_description;
var add_mod_cat = current.variable_pool.add_model_category;
var add_mod_no = current.variable_pool.add_model_no;
var add_owner = current.variable_pool.add_product_owner;
var add_status = current.variable_pool.add_status;
var add_cat_desc = current.variable_pool.add_catalog_desc;
var grModel = new GlideRecord('cmdb_model');
if(grModel.get(mod_name_ref))
{
var actualdata1 = grModel.name;
gs.log('actualdata1'+actualdata1);
gs.log('grModelDispl==>'+grModel.name.getDisplayValue());
var actualdata2 = grModel.model_number;
gs.log('actualdata2'+actualdata2);
if(actualdata1 != mod_name_ref || actualdata2 != add_mod_no)
updateRequired = true;
if(updateRequired == true)
{
// grModel.name = mod_name_ref;
grModel.manufacturer = add_manufact;
grModel.short_description = add_short_desc;
grModel.cmdb_model_category = add_mod_cat;
grModel.model_number = add_mod_no;
grModel.owner = add_owner;
grModel.status = add_status;
grModel.description = add_cat_desc;
grModel.update();
}
}
Any help