When the state of sc_task changes to close complete the variables should be manadtory and visible
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2025 03:20 AM
Hi,
I have a requirement, if the state is closed complete then the one variable should be mandatory and visible but in my case two task will get created for same RITM, when the first task closed the input in the variable should get passed to second task and it should be read only.
Its a random case like when in the fist task if the end user click on close complete of task first and without saving he changes to WIP or pending etc then the variable should get clear.
Please help me with the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 12:10 AM
hi @jyotisaroj
Mandatory Variable based on State:
- Create a Client Script on the task table that checks if the state of the task is 'Closed Complete'. If it is, you can make the specific variable mandatory and visible.
function onChange(control, oldValue, newValue) { if (current.state == 'Closed Complete') { g_form.setMandatory('your_variable_name', true); g_form.setVisible('your_variable_name', true); } else { g_form.setMandatory('your_variable_name', false); } }
Passing the Variable to the Second Task:
- On the first task, create an On Close Business Rule that copies the value of the variable to the second task when the first task is closed.
// Business Rule on Task Table if (current.state.changes() && current.state == 'Closed Complete') { var secondTask = new GlideRecord('your_task_table'); if (secondTask.get('sys_id', current.sys_id)) { secondTask.your_variable_name = current.your_variable_name; // Copy variable secondTask.update(); // Save the second task } }
Make Variable Read-Only in the Second Task:
- Create another Client Script for the second task and set the variable as read-only.
function onLoad() { if (current.task_condition) { // Update this condition to check for the second task g_form.setReadOnly('your_variable_name', true); } }
Clearing the Variable:
- Add an additional client script or modify the existing one to clear the variable if the state changes from 'Closed Complete' to 'WIP' or 'Pending' before saving.
function onChange(control, oldValue, newValue) { if (oldValue == 'Closed Complete' && (newValue == 'WIP' || newValue == 'Pending')) { g_form.setValue('your_variable_name', ''); // Clear the variable } }