Assigned to

Anusha Medharam
Tera Contributor
when engineer click on UI button remove his name from assigned to in all open cases and state changes to open how to achieve in servicenow. let me know the solution
 
 
 
5 REPLIES 5

Dibyaratnam
Tera Sage

You can achieve it via UI Actions(sys_ui_action). 

Write the server script where in it will fetch the logged in user name and empty the assigned to field in the required table and update the state to open.

Jayant_M
Kilo Sage

Hey @Anusha Medharam ,

 

Write one server side ui action with following code

 

var a=gs.getUserID();

var icRec= new GlideRecord('Table name');

icRec.addQuery('state','open');

icRec.addQuery('assigend_to', a);

while(inc.next()){

icRec.assigned_to='';

icRec.update();

}

 

Please mark my response helpful if it resolves your issue

Sandeep Rajput
Tera Patron
Tera Patron

@Anusha Medharam Here is the script for you.

 

unAssignCase();
function unAssignCase() {	
    var caseRec = new GlideRecord('sn_customerservice_case');
    caseRec.addQuery('assigned_to',gs.getUserID());
    caseRec.addQuery('state','10'); //Open state
    while(caseRec.next()){
     caseRec.setValue('assigned_to','');
     caseRec.update();
    }
	action.setRedirectURL(current);
}

Hope this helps.

Rajdeep Ganguly
Mega Guru


To achieve this in ServiceNow, you would need to create a UI Action that triggers a script. This script would find all open cases assigned to the current user and then remove the user's name from the 'Assigned to' field and change the state to 'Open'. Here's a step-by-step guide:

1. Navigate to System UI > UI Actions in ServiceNow.
2. Click on New to create a new UI Action.
3. Fill in the necessary fields such as Name, Table (probably 'incident' in your case), and Action name.
4. In the 'Script' field, you would write a script similar to the following:

javascript
var userID = gs.getUserID(); // get the sys_id of the current user
var gr = new GlideRecord('incident'); // create a new GlideRecord on the 'incident' table
gr.addQuery('assigned_to', userID); // add a query to find incidents assigned to the current user
gr.addQuery('state', '!=', 7); // add a query to find incidents that are not closed
gr.query(); // run the query

while(gr.next()) { // loop through the results
gr.assigned_to = ''; // remove the assigned_to value
gr.state = 1; // change the state to 'Open'
gr.update(); // update the record
}


5. Make sure the 'Client' checkbox is unchecked, as this is a server-side script.
6. Click on Submit to save the UI Action.

Please note that this is a basic example and might need to be adjusted to fit your exact needs. Always test scripts in a non-production environment first.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER