How to fetch Sys property values in client script

Saranya2
Tera Contributor

Hi All,

We have a custom field on the knowledge form called "Content Owner Group", If "Ownership Group" is from one of the specific groups( around 100 groups), I need to populate the  Content Owner Group  as "XYZ" group.

I cannot use UI policy, Got some idea from community  Client Script + Display BR to achieve this.

I have created new system property and defined all the Ownership Group sys ids, But I am not sure how to fetch Sys property values in client script to achieve the requirement.

Can anyone help me on this or is there any other way to achieve this?

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please do the below:-

 

Write a display BR with below code:-

 

Saurav11_0-1667412405045.png

 

 

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

	g_scratchpad.my_property = gs.getProperty('propertyname');

})(current, previous);

 

 

The on the onchange client script  of Ownership Group field call it using the below code:-

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   var myProperty = g_scratchpad.my_property;
   if(myProperty.indexof(newValue)>-1)
	   {
		   g_form.setValue('Content Owner Groupfieldname','sysidofxyzgroup');
	   }

   
}

 

 

Please mark my answer as correct based on Impact

View solution in original post

8 REPLIES 8

Hello,

 

Also create a onload client script with the below code:-

 

function onLoad() {
  
var myProperty = g_scratchpad.my_property;
var grpname=g_form.getValue('ownershipfieldgrpname');
if(grpname!='')
{
   if(myProperty.indexOf(grpname)>-1)
	   {
		  g_form,setReadOnly('contentgrpfielname',true);
	   }

}

 

Please mark my answer as correct based on Impact.

Hi @Saurav11,

It is working fine, I need this functionality for knowledge blocks as well, Can we modify this on load & on change script without creating new script for knowledge blocks?

I found the  "Class" field on knowledge table, but we are not enabled that field on the form, Can we achieve this without creating new script?

hello,

 

If any field is on the same table then yes you can use the same script.

 

Please mark my answer as correct based on Impact.

Sagar Pagar
Tera Patron

Hi @Saranya2,

 

Take a look at my one of the article related to System properties and its usage. It will help you.

System Properties 

 

Thanks,

Sagar Pagar

The world works with ServiceNow