how to update recurring price in ci table from flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 10:11 PM
I have used the below code to populate the recurring price of the catalog item in cmdb_ci table. In the workflow i used the below code and it worked.
Thankyou
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 04:31 AM - edited 01-31-2024 04:33 AM
Good day,
The code you referenced as working in your workflow (below) currently isn't querying the "cmdb_ci_spkg" table...
var rec = new GlideRecord("cmdb_ci_spkg");
rec.u_recurring_price=current.recurring_price;
As you're missing something similar to...
rec.addQuery("name", current.name);
rec.query();
However, if you're upgrading from a Workflow to a Flow. I recommend you use the "Update Record" flow action. This will make things far more maintainable moving forward and probably won't require any code at all. I've attached a simple example of what that might look like.
1 - Using the "Look up record" action you can find whatever record you're basing the new recurring price on. This will be whatever your workflow considers "current" in your legacy example.
2 - Using the "Update record" action you can find whatever record you'd like to update the price of. This will be the record on the "cmdb_ci_spkg" table in your legacy example.
3 - Using the "Fields" condition builder within the "Update record" action, you can select "Recurring Price" and then you can set that value to whatever it needs to be. In my example, I'm linking it to the Recurring Price of the record I found in step 1.
This approach may seem like a few extra steps now, but it is much easier to maintain and scale. It also aligns to ServiceNow recommended best practice. If you're going to be updating multiple records at a time, you can put the above inside a for each loop within the flow designer using the "Flow Logic" actions.
If you absolutely must use some code then it'll probably need to look something like this...
var rec = GlideRecord("cmdb_ci_spkg");
rec.addQuery( <your condition to find the record you want to update> )
rec.query();
while(rec.next()){
rec.setValue("u_recurring_price", <whatever you're GETTING a price from>);
rec.update();
}
If this has been helpful, please mark it as the solution!
Kind regards,
Brad