User Requirement Could you plz provide code

mahesh_03
Tera Expert
  1. Create a new UI Action on Change Request - Create Task
  2. This button should be visible only in New/Assess state and to the Assignee of the ticket.
  3. When user clicks on Create Task, user should be redirected to new Change Task form and below fields should be copied from Change Request to Change Task:
    - Configuration Item
    - Short Description
    - Description
    - Assignment Group 
    - Assigned To
  4. If there is already an active Change Task for the same Configuration Item, stay on the Change Request form and display an Error Message - "Change Task is already active for the same Configuration Item".
8 REPLIES 8

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @mahesh_03 

 

  1. Create a new UI Action on Change Request - Create Task

Atul: On change request we already have related list named change task and there you will find New Button.

  1. This button should be visible only in New/Assess state and to the Assignee of the ticket.

Atul: You can modify the behaviour of that UI action

  1. When user clicks on Create Task, user should be redirected to new Change Task form and below fields should be copied from Change Request to Change Task:
    - Configuration Item
    - Short Description
    - Description
    - Assignment Group 
    - Assigned To

Atul : check OOTB logic.

  1. If there is already an active Change Task for the same Configuration Item, stay on the Change Request form and display an Error Message - "Change Task is already active for the same Configuration Item".

Atul: Add behaviour, with loop to check is any active task and show message.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Harish KM
Kilo Patron
Kilo Patron

Hi @mahesh_03 please find the below UI Action for the same, follow the steps as per screen shot and copy the script shared

HarishKM_0-1706944214920.png

 

UI Action cond: (current.state == -5 || current.state == -4) && current.assigned_to == gs.getUserID()

Script:

function reDirectToCHG() {

        var sysID = g_form.getUniqueValue(); //CHG sysID
        var desc = g_form.getValue('description'); //CHG desc
        var sd = g_form.getValue('short_description'); //CHG short desc
        var ci = g_form.getValue('cmdb_ci');
        var grp = g_form.getValue('assignment_group');
        var assigned_to = g_form.getValue('assigned_to');

        //Base URL for creating a new CHG Task record and to map fields via 'sysparm_query' parameter
        var url = '/change_task.do?sys_id=-1&sysparm_query=';

        //Query parameter to map fields on CHG form.
       var urlParams = 'change_request=' + sysID + '^description=' + encodeURIComponent(desc) + '^short_description=' + encodeURIComponent(sd) +'^cmdb_ci='+ci +'^assignment_group='+grp +'^assigned_to='+assigned_to;
        //Open CHGTask in new window
        g_navigation.open(url + urlParams, '_blank');
    }
Regards
Harish

I checked the above code not working as expected could you please check it once 

Hi @maheshchokkara the shared code works fine in my PDI. you can share your entire UI action we can check

Regards
Harish