- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 05:45 PM
Hi Team,
I have fields ("u_affected_contact"), ("u_requestor") & ("company") in the sc_request table. I have a business rule to check if the ("u_affected_contact") field is empty. I am not 100% confident with the syntax and i would like help with it.
The company field basically populates itself based on the ("u_affected_contact").
What i want to do --->
- Check if ("u_affected_contact") is EMPTY
- If EMPTY, then ("company") should be populated based on ("u_requestor") -- ("u_requestor" --> company)
- ELSE do nothing
All help is appreciated.
Thank you!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 05:55 PM
You are running BR on sc_request, so there is no need of creating another object of sc_request. "current" is your current object. Script will go something like below
if(current.u_affected_contact.nil()){
gs.log(" I am Here");
current.company = current.u_requertor_company
}
more on nil()
GlideElement - ServiceNow Wiki
Mark your feedback( Like or Helpful or Correct) as per the impact of my response. Cheers!
Vab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 06:14 PM
Did it work?
Mark your feedback( Like or Helpful or Correct) as per the impact of my response. Cheers!
Vab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 06:16 PM
Hi Vab,
Just tested it out and it works!!! Awesome work team!
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2021 12:02 PM
Hii vab.13,
I was trying to do like if assigned to is empty the state should be in 'In progress'
else state should be active.
I was trying the same code your write here but it is not working in BBR
if(current.assigned_to.nil()){
current.state.changesTo(2); // 2 is the value of 'In Progress' choice
}
else
{
current.state.changesTo(4); //4 is a value of 'Active' choice
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2017 06:09 PM
There are few things I noticed in your script.
1. Alert never works in business rule. Its a client side method.
2. The other thing is that you need to pass u_affected_contact and validate if its not empty. This can be done via below script.
3. Since you are writing a business rule there is no need to write a GlideRecord. This can be done via dot walking.
You can simply write this script and it should work for you
if(current.u_affected_contact == "")
{
current.u_company = current.u_requestor.company
}
else
{
//do nothing
}