How to set default value via gs.getproperty(), and set the value on field on the form

Rajababu
Giga Guru

How to set default value via gs.getProperty(), and set the value on field on the form when field have "null" value.

For example , "Email User Name" field on the incident form.

I have created sys_property with sys_id ,now client required whenever field "Email User Name" will be blank /Null, then set the system property .

Thanks,

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Do you mean like you are applying gs.getProperty('some_property'), this actually does not exist or is null, so you would like a default value instead?

You can use:

var x = gs.getProperty('some_property') || 'Your default value';

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

6 REPLIES 6

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Do you mean like you are applying gs.getProperty('some_property'), this actually does not exist or is null, so you would like a default value instead?

You can use:

var x = gs.getProperty('some_property') || 'Your default value';

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

There is field on scoped application HRSM ,HR CHANGE there is field name "Email Name User " field .

I have created system property  which contain sys_id .

Now ,

If "Email Name User" if blank then, it will set to the "system property" .

Ankur Bawiskar
Tera Patron
Tera Patron

@Rajababu

You will have to use either default value in the field dictionary or before insert BR

BR Script:

(function executeRule(current, previous /*null when async*/) {

    // Add your code here

// give valid field name here

if(current.email_user_name == ''){

current.email_user_name = gs.getProperty('property_name');

}

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Rajababu 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

If not, please let us know if you need some more assistance.

Thanks!
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader