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

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

Hi @Saurav11,

I have tried as you have mentioned, I am getting on Change script error as below, Please see below attachments.

 

vg.PNG

 

 

vg1.PNG

 

vg2.PNG

 

 

Hello,

 

Sorry It would be indexOf(capital O)

 

so the code will be as below:-

 

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. 

Hi @Saurav11,

It is working now, I have one more case, if "Content owner group" is populated based on "Ownership group", then users should not be able to modify the "Content owner group" field. In the on change client script I made "Content owner group" as read only, But after saving the form, the field will be editable. Users are able to modify that field, it should not happen. how to achieve this?