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

When a catalog item is requested, a "catalog request" will be created. When this request is approved, automatically corresponding "Request items" also will approve. If the request price is < 1000$, SNOW has a default workflow "Service Catalog Request", which will automatically approves the request.



You need to create a workflow for "Request item", After "Approved", you can have a "Run script" component, which allows you to run your own script against that request item. In that "Run script", you can have the code to copy the item properties to asset values. Once this workflow is created, this workflow must be set to that "Catalog item".




Here is an example workflow, we have for "catalog request item",



Screen Shot 2016-07-11 at 10.11.39 am.png



If you want to have your "Request" to be approved separately from default workflow, then you need to create 2nd workflow for "Request", which sends request to "Approvers" group. For that You can create a almost replica of "Service catalog request" workflow.


malu
Tera Contributor

Thanks Ram ...Really it helps me a lot.


In my case


1. Request will be auto-approved, Only requested item will be set to approval group. ( This can be created as per your suggestion).


2. Now after RITM is approved. I need to run a script to pull all the variables like model_name, model_number, manufacturer...etc ( catalog item variables) and update the existing model record and also i need to check whether the changes are really made or same for that model record ( Can you help me sample script ).


Any help!!


How do you want to get the model record? What is the unique identifier here? Model number or model name?


Thanks Abhi for checking this.


Here we have a catalog item which has Model name which is a unique identifier.


In this catalog item we have Model Name , Model number, Manufacturer, owner, short description of the model record are the variables.


When users filled in these catalog items then approval will be triggered on Requested Item ,once approved all the values (variables values) should be pulled and create a new model record in model table.