Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

In The Change Form in Schedule Planned start date and End Date should Editable for particular XYZ Gr

nameisnani
Mega Sage

Hi All ,

 

In The Change Form in Schedule Planned start date and End Date should Editable for particular XYZ Group for entire change cycle they can able edit .

 

Notes - 

I Think i need to write OnChange Cilent Script 

  - I need to Get Current Logged in user 

  - I Need to check whether that user belongs to XYZ Group 

  - If user = XYZ Group , then user can able to edit schedule planned start and date .

  - If user != XYZ Group , then it should  read only .

 

* We have to do this for this particular XYZ Group .

* For some groups they have made readonly by using UIPolicy , 

* I have tried UIPolicy It doesn't work ,

* We need to write Cilent script 

 

SunilKumarPadh_0-1667351748681.png

Please help me 

 

@Saurav11 @kamlesh kjmar @Radhika Aluru 

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please do the below:-

 

Create a display BR on change request table with below code:-

 

Saurav11_0-1667358384149.png

 

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

	g_scratchpad.group='false';
	if(gs.getUser().isMemberOf('Database'))
		{
			g_scratchpad.group='true';
		}

})(current, previous);

 

Then in the existing UI policy you have just delete the UI policy action from it:-

 

Saurav11_1-1667358438164.png

 

And then in the UI policy itself in the execute if true section use the below code:-

 

Saurav11_2-1667358509100.png

 

 

function onCondition() {
    var group = g_scratchpad.group;
	alert(group);
    if (group == 'true') {
    g_form.setReadOnly('start_date',false);
    g_form.setReadOnly('end_date',false);
    } else {
    g_form.setReadOnly('start_date',true);
    g_form.setReadOnly('end_date',true);
    }
}

 

 

Please mark my answer as correct based on Impact.

 

View solution in original post

7 REPLIES 7

Hi @Saurav11 

 

Thank you it's worked out 

Great tutorial, thank you. If it's for adding a role, remember to add it in the access control.

sujata sakhare
Tera Contributor

hello,

Create a display BR on change request table

try this code is executed on my PDI

g_scratchpad.group='false';
	if(gs.getUser().isMemberOf('Database'))
		{
			g_scratchpad.group='true';
		}

Then Write UI policy

function onCondition() {
    var group = g_scratchpad.group;
	alert(group);
    if (group == 'true') {
    g_form.setReadOnly('start_date',false);
    g_form.setReadOnly('end_date',false);
    } else {
    g_form.setReadOnly('start_date',true);
    g_form.setReadOnly('end_date',true);
    }
}

Thanks.

Please mark my answer as correct based on Impact.