- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2014 08:15 AM
Hi there!
I have two fields: assigned_to, and u_previously_assigned_to.
Should I make a business rule, or a client script?
What I need to happen, is when the Incident state changes to "Retired", then copy the field values from the field "assigned_to", and put it in the new field "u_previously_assigned_to", due to the assigned_to field may change upon the state change.
Anyone have anything that already does something like this? I wrote up something quick in a business rule running as "before", but it isn't changing the new field. It is just blank.
Thanks for your help!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2014 12:41 PM
I got it! Strangely I needed to add the current.update(); that you said I didn't need to use... put it in my script and bam, it worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2014 08:30 AM
I think it would depend on when you want to set the value. Are you looking to set the value upon save? Or instantly when the field on the form is changed?
If you are looking to set them upon save then either (Business Rule or Client Script with onSubmit) is possible. If you are looking to instantly change it (like the moment a user selects Retired on your form, before they save) then a OnChange Client Script is the way to go.
For a business rule, a before seems fine (since you are modifying the current record):
1) Use the condition field so it does not always run: e.g.: current.state == "YOUR_RETIRED_VALUE" && current.state.changes()
- Use the .changes so that it does not fire when a Retired record is updated. Not sure if that's a requirement or not
2) current.u_previously_assigned_to = current.assigned_to;
- Make sure that the field you created is of the same type (reference to user), otherwise you might need to get the display value or something for a plain-text name
You do not need a current.update() on the before query.
Also make sure you do not have any other business rules running before that set the value (causing it to be blank). Put some debugging/logging into your code and see what the variables say, I always find that an easy way to solve a problem.
If you post the code you have that does not work I am sure we can help with the exact code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2014 08:36 AM
you have access to previous in a before BR so you could use.
current.u_previously_assigned_to = previous.assigned_to
this would populate that field with the value in assigned_to before it changed.
Marc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2014 08:40 AM
I actually did find a business rule that is setting it to blank. Should I make this business rule run before it by changing the order to a lesser number?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2014 09:36 AM
I think you have reached the point where there may be multiple solutions to your problem.
You could change the order of them so that your new business rule runs first, sets the appropriate value in the custom assigned to field, then allows the other business rule to modify the default assigned to.
Or, you could use the "previous." as indicated above. I think a limitation with that would be if the assigned to was changed at the same time the state was set to retired, it would use the old assigned to. So I am not sure if that would be best.
If it were me I would use the order to adjust which business rules run first so that I can keep using "current.". Because the sole purpose of this business rule is to set a custom field, you do not care what happens to the default field after and setting the order appropriately will achieve this.
I am sure there are other solutions, but this is what I think I would do. Or at least try first.