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

ramireddy
Mega Guru

I looked at your instance(Not sure whether i can login like that as per this forum guidelines). What i found is: When user is trying to "Update" existing model, you are hiding "Model Name" text box. When i select "edit" radio button, "Model Name" textbox is getting hidden. I believe it is not intentional. you are planning to allow users to update "name" as well. If so, you shouldn't hide it. (I am not able to find the place, where you written the code to hide this. Please unhide it).



Here are the 2 changes I made.



1.   For the "catalog item", there are   2 model name variables with different ids though.


AR_add_model_name


AR_add_model_name_ref



I changed name of "AR_add_model_name_ref " to "Select Model" for better USER experience.



2. In the workflow, in 2nd run script section, Line 4 and 27 are updated. I just read "Model name" into a variable and used it for updating. can you try?



When you unhide that text box, it should work as you intended.


malu
Tera Contributor

Thanks Ram for checking this. The reference field is intentional because when user click on add option and then if they mistakingly select the model then new model will gets created with empty. So i tried to hide it thro' UI Policy.


If you are hiding "model name", thus not allowing "name" to be updated for existing model, then I believe everything is alright. What is the issue you are facing now?


Thanks


Rami Reddy


malu
Tera Contributor

Might be this would be last Q in this thread before i mark correct. The issue is that whenever I tried to update the existing model i can see a updated Model into the Maintain Items list. e.g.:- when i update any model like Alienware M14x by changing some fields i can see this model into the Maintain Items list why is this happening? any idea?


Can you please provide a screenshot, which shows this issue. I am not able to replicate this.