Approval and record update Workflow

malu
Tera Contributor

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?

1 ACCEPTED SOLUTION

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();


  }
}


View solution in original post

21 REPLIES 21

Hi Ravi,



I am not sure, whether I understood requirements mentioned in the above post. It asks questions on 2 areas.



1. Comparing values in 2 arrays - As arrays contains elements only. But in this scenario, you wants to compare "property name" and "value" combination. So, you should use objects to compare. Here is an example to compare 2 objects. You need to create 2 objects, one with old values and other with new values, then use JSON.stringify method to convert them to string and compare. However, if there are not many fields to compare, I suggest to stick with individual fields only instead of doing like this.



Object comparison in JavaScript - Stack Overflow



2. Updating model name - I think, you have a catalog item, which allows to insert a new model as well as updating existing model. If the model exists already you wants to update that record or else create new record. For "Update" scenario, you should pass "model name" from client to server   and update "name" column. You are trying to update "sys id" itself in name column, which is incorrect. So, pass "model name" also from client and use that value to update "model name" column



Thanks


Rami Reddy


malu
Tera Contributor

Thanks Ram....


For the point 1 , I will go with the individual fields as of now.


For the point 2, I'm not clear where I'm wrong. you are correct I have a catalog item which allows to insert a new model as well as updating existing model. Do you want me to go with GlideAjax to pull the value?


You should pass "name". However, I guess you are using this in "workflow". So, "Name" is supposed to be a "catalog variable". You should get the name from catalog variable with the syntax "current.variable_pool.add_model_name"



Once you identified, whether to update or insert, you need to assign the catalog variable value to table field.



grModel.name = current.variable_pool.add_model_name;



Check, what's the variable name for "Name" of model and use the same.


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();


  }
}


Abhinay Erra
Giga Sage

Ravi,



  Create a Run script activity in the workflow and update the asset record by using GlideRecord methods.