How to set a default value based on condition

Katie A
Mega Guru

Hello, Is there a way to set a default value ONLY if certain conditions on the record are true?

As an example, I want to set a default value on an Asset Tag ONLY if the CI type is not a network adapter or storage.

Thanks!

1 ACCEPTED SOLUTION

Yes, you can do that with an After business rule.


conditions: Is Virtual is true


script: set your default value here


View solution in original post

6 REPLIES 6

venkatiyer1
Giga Guru

Hi,



You can use a client callable script include function that returns the value based on the condition.



something like javascript: getDefaultAssetTag()


Hi Venkat, I am having a timing issue with this solution. The record needs to be created first and then the default value needs to be set.



I want to set a default value on an asset tag if the "Is Virtual" flag is FALSE.



The record must be created with the is virtual flag first then the default value can evaluate the condition. Is there a way I can do that with an "after" business rule?



Thanks!


Yes, you can do that with an After business rule.


conditions: Is Virtual is true


script: set your default value here


One note about Abhinay's response - I would change this from an AFTER business rule to BEFORE.



BEFORE rules are generally used to manipulate the current object, then you get an implicit update following it.



current.u_my_field = 'Some value';



AFTER rules are generally used to manipulate other records (typically they will have a GlideRecord query in there somewhere) AFTER your record has been updated. If you put the current.u_my_field statement in an AFTER business rule, it will require a current.update() to get it saved to the database. current.update() is going to retrigger ALL the business rules again for that record - wasting a lot of time and generating a Recursive Business Rule error.



FYI - The condition remains unchanged.