Business rule script to check if reference field is empty

thiraj
Tera Contributor

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

find_real_file.png

All help is appreciated.

Thank you!

1 ACCEPTED SOLUTION

vab_13
ServiceNow Employee
ServiceNow Employee

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


View solution in original post

13 REPLIES 13

thiraj
Tera Contributor

Hi Vab.



Gave it a try. Still no luck. I am not getting the alert at all which means it is not reading it!!



find_real_file.png


Thank you


vab_13
ServiceNow Employee
ServiceNow Employee

try gs.log. If you have a look: I had "gs.log" in the script.


It is not possible to display pop up window using business rule as it runs in server side.


thiraj
Tera Contributor

Hi Vab,



Where can i see the output of gs.log()?



Thank you


thiraj
Tera Contributor

find_real_file.png


vab_13
ServiceNow Employee
ServiceNow Employee

yes, this should work


It will print here:


find_real_file.png