Change task state needs to be read only for a specific type of task, please help.

snow_beginner
Mega Guru

Hi,

 

The requirement is that when a change task of type=peer review is created on a change, the state needs to be read only for everyone except admin and based on the result of the field peer review result (pass or fail) the state needs to be set to closed. Note: The state field on the change_task table comes from the task table. 

 

I have made an onChange client script for setting the state to closed if peer review result=pass or fail

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

   //Type appropriate comment here, and begin script below
   if (newValue=='Pass'||newValue=='Fail'){
	g_form.setValue('state', 3);
   }
   
}

 

I have also made another onLoad client script for state to be read only for all except admin

function onLoad() {
   //Type appropriate comment here, and begin script below
   if (!g_user.hasRole('admin')){
	g_form.setReadOnly('state', true);
   }
}

However, making the onLoad client script has set the state to read only for all types of change tasks and not just the peer review type.

 

So, I made a dictionary override but then the state was set to read only for this type of task but it was for everyone including admin. 

 

Is there any way to make the state read only another way for all except admin for this change task type. Doing the dictionary override does not give admin right to change it back, doing the onLoad client script makes it for all the task types.

 

Thanks.

1 ACCEPTED SOLUTION

J Siva
Tera Sage

Hi @snow_beginner 

You just need to do one more check in your OnLoad client script to check the Change task type. PFB.

function onLoad() {
    var role_flag = g_user.hasRole("admin");
    var type = g_form.getValue("change_task_type"); // get the task type

    g_form.addInfoMessage("Role Flag : " + role_flag);
    g_form.addInfoMessage("Task type : " + type);
    if (!role_flag && type == "implementation") { //  check the task type. I've used "Implementation" type. You can change it to "Peer review"
        g_form.setReadOnly('state', true);
    }
}

Output:

JSiva_0-1742912930365.png

Hope this helps.
Regards,
Siva

View solution in original post

3 REPLIES 3

J Siva
Tera Sage

Hi @snow_beginner 

You just need to do one more check in your OnLoad client script to check the Change task type. PFB.

function onLoad() {
    var role_flag = g_user.hasRole("admin");
    var type = g_form.getValue("change_task_type"); // get the task type

    g_form.addInfoMessage("Role Flag : " + role_flag);
    g_form.addInfoMessage("Task type : " + type);
    if (!role_flag && type == "implementation") { //  check the task type. I've used "Implementation" type. You can change it to "Peer review"
        g_form.setReadOnly('state', true);
    }
}

Output:

JSiva_0-1742912930365.png

Hope this helps.
Regards,
Siva

@J Siva thanks so much, that has resolved the problem.

Glad to hear that it helped!