How to populate value in any field using if condition

serviceganga
Tera Contributor

Can any one help me out in finding the solution to populate value in any field using if condition.

Ex. if sys_id is xxxxxxxxxx, short description should be 'abcd'

if sys_id is yyyyyyyyyy, short description should be 'apple'

I want to check both the condition.

Help is appreciated.

Thanks & Regards,

Ganga Bhavani

3 REPLIES 3

Dave Smith1
ServiceNow Employee
ServiceNow Employee

sys_id of what?



Sounds like a simple client scripting problem... but could do with a clearer problem definition before offering up a solution.


darius_koohmare
ServiceNow Employee
ServiceNow Employee

Hi Ganga,


Two common ways this would be done:



#1 Using a Business Rule


You can use a business rule that runs server side so on the insert or update of the record, you can check the exact conditions you would like.


If the condition is met, you can run a specific action you desire (e.g. set short description to abcd).


Business rules



#2 Using a Client Script
If you want more real-time changes, meaning as the user fills in the form have it change the value, then you need to use a onChange client script.


Client scripts


Steven Parker
Giga Sage

Something simple like this is one we use for an "if this or this" statement in a task in a workflow:



    if (current.variables.app == 'Xpress Account' || current.variables.app == 'Harland Clarke') {


              task.short_description = "ABCD";


    }else{


              task.short_description = "APPLE";


      }



Similar could be done in a client script to set a field on the form equal to something for onLoad, onChange, etc..



if(typeofrequest == 'position_change' || typeofrequest == 'new_hire'){


    g_form.setValue('job_function','ABCD');


  }else{


    g_form.setValue('job_function','Apple');


  }




These are just examples of stuff we are using



Please mark this response as correct and/or helpful if it assisted you with your question.
Steven