The CreatorCon Call for Content is officially open! Get started here.

Set field value on current in Display Business Rule

mennoaret
Kilo Explorer

Hi all,

I'm having the following problem with a Display Business Rule.
The idea is that a field will be prefilled with the current user on a existing record.
So in my Business Rule I wrote:



current.assigned_to.setValue(gs.getUserID());

Now if the user opens the incident, the assigend to field is filled with his/her name.
But if this user hit the update button the changes are not saved to the record.
I think this is because Service-Now does not see any form changes from the client.
I also tried to add:


current.setForceUpdate(true);

but without any luck.

I have resolved this issue by filling the scratchpad with the value for the assigned to field and created a onload client script to fill this scratchpad variable to the field, but this is not what I would prefer.

I hope someone can help me out.
Thanks in advance.

4 REPLIES 4

HarshTimes
Tera Guru

Hi
First if you want to set the assigned to field to the logged in user,Just put this in default value of the field :-javascript:gs.getUserID()
you dont need to put any other script.


Hi Harsh,

Thanks for your reply.
I know the default value option but I want to fill the value only in some specific cases.
We also have a display Business Rule for a new record and then the values are saved, but not when updating existing record.

Kind regards,
Menno Aret


Please share your script


Hi Harsh,

I just created an example on demo018.service-now.com
simple Display Business Rule:
https://demo018.service-now.com/nav_to.do?uri=sys_script.do?sys_id=4ffbe11db9841d00064bce41d5462fae

Take a look at the incidents:
https://demo018.service-now.com/incident_list.do?sysparm_userpref_module=b55fbec4c0a800090088e83d7ff500de&sysparm_query=active=true^EQ&active=true

Check INC000000321784, short description will not change if you just open the record and hit update. But the short description was filled with "Test from Menno".

Now create a new incident and hit submit, the record is saved with the correct short description from the Display Business Rule.
I hope you understand my problem.

Kind regards,
Menno Aret