Scripts d’affectation d’approbation
Il s’agit d’une version consultable des scripts d’approbation et d’affectation utiles.
Avertissement :
La personnalisation décrite ici a été développée pour une utilisation dans des instances spécifiques, et n'est pas prise en charge par Now Support. Cette méthode est fournie telle quelle et doit être testée rigoureusement avant d'être implémentée. Publiez toutes les questions et commentaires concernant cette personnalisation dans notre forum communautaire.
Pour voir Viewing my approvals.
- Affecter un groupe pour les demandes ESS
-
Le script de règle d’affectation suivant affecte automatiquement un groupe pour toutes les demandes ESS.
if(current.opened_by.roles==""){ current.assignment_group.setDisplayValue('Network'); current.update();} - Affecter un élément de catalogue au groupe en fonction de la tâche du plan d’exécution
-
Cette règle d’affectation affecte un élément de catalogue de services au groupe de base de données s’il utilise un plan d’exécution dont une tâche de catalogue est affectée au groupe de bureau.
//Return catalog items that have no group but do have a delivery plan assigned var ri =new GlideRecord("sc_cat_item"); ri.addQuery("group","=",null); ri.addQuery("delivery_plan","!=",null); ri.query(); while(ri.next()){ gs.log("Found an item"); //Return tasks that point to the same delivery plan as the above item var dptask =new GlideRecord("sc_cat_item_delivery_task"); dptask.addQuery("delivery_plan","=",ri.delivery_plan); dptask.query();while(dptask.next()){ gs.log("Found a task");var gp = dptask.group.getDisplayValue(); gs.log(gp);//If the task is assigned to desktop, assign the item's group to desktop if(dptask.group.getDisplayValue()=="Desktop"){ ri.group.setDisplayValue("Desktop"); gs.log("updating "+ ri.getDisplayValue()); ri.update();break;}}} - Affecter des éléments à une seule tâche
-
Cette règle d’affectation affecte automatiquement tous les éléments de catalogue ayant une seule tâche associée à un groupe particulier.
//Get the catalog item for the current requested item var scCatItem =new GlideRecord("sc_cat_item"); if(scCatItem.get('sys_id', current.cat_item)){ // If the catalog item already has an assignment group or if using workflow we don't need to make an assignment if(!scCatItem.delivery_plan.nil()&& scCatItem.group.nil()){ var dpTask =new GlideRecord("sc_cat_item_delivery_task"); dpTask.addQuery("delivery_plan","=",scCatItem.delivery_plan); dpTask.query(); if(dpTask.getRowCount()==1&& dpTask.next()){ // Check that there is only 1 record in the GlideRecord dpTask.group;}}} - Affectation basée sur la charge de travail
-
Type : règle métier.
Description : renseignez le champ Affecté à en fonction du membre du groupe d’affectation qui a le moins d’incidents actifs.
Paramètres :- Ordre : 1 000 > si vous souhaitez exécuter après les règles d’affectation
- condition : current.assigned_to == '' && current.assignment_group != ''
- Quand : avant, insérer/mettre à jour
var assignTo = getLowestUser(); gs.addInfoMessage("assigning to is "+ assignTo); current.assigned_to= assignTo; function getLowestUser(){ var userList =new Array(); var cg =new GlideRecord('sys_user_grmember'); cg.addQuery('group', current.assignment_group); cg.query(); while(cg.next()){ var tech = cg.user.toString(); var cnt = countTickets(tech); gs.addInfoMessage("Tech counts "+ cg.user.name+' '+ cnt +" "+ tech); userList.push({ sys_id: tech,name: cg.user.name, count: cnt });} for(var i=0; i < userList.length; i++){ gs.addInfoMessage(userList[i].sys_id+" "+ userList[i].name+" "+ userList[i].count);} userList.sort(function(a, b){ gs.addInfoMessage("Sorting: "+ a.sys_id+"("+ a.count+"); "+ b.sys_id+"("+ b.count+")"); return a.count- b.count;}); if(userList.length<=0)return""; return userList[0].sys_id;} function countTickets(tech){ var ct =new GlideRecord('incident'); ct.addQuery('assigned_to',tech); ct.addQuery('active',true); ct.query(); return ct.getRowCount();} - Exécuter des règles d’affectation lorsque la catégorie est modifiée
-
Type : Script client.
Table : Incident.
Description : cet exemple est un script client onChange dans le champ Catégorie dans Incident. Remarque : ce script est utilisé pour utiliser AJAX synchrone (le comportement asynchrone est spécifié par le troisième paramètre de l’appel ajaxRequest). L’implémentation ci-dessous utilise AJAX asynchrone. L’inconvénient de l’utilisation de la version synchrone est qu’un problème de réponse réseau peut entraîner le blocage du navigateur.// Make an AJAX request to the server to get who this incident would be // assigned to given the current values in the record. This runs the assignment // rules thathave been defined in System Policy and returns the assigned_to and // the assignment_group function onChange(control, oldValue, newValue, isLoading){ if(isLoading){return; // No change, do not do anything } // Construct the URL to ask the server for the assignment var url ="xmlhttp.do?sysparm_processor=AJAXAssignment&sys_target=incident"; var uv = gel('sys_uniqueValue'); if(uv){ url +="&sys_uniqueValue="+ uv.value;} // Make the AJAX request to the server and get the response var serial = g_form.serialize(); // get all values currently assigned to the incident var response = ajaxRequest(url, serial,true, responseFunc);} // This callback function handles the AJAX response. function responseFunc(response){ varitem= response.responseXML.getElementsByTagName("item")[0]; // Process the item returned by the server if(item){ // Get the assigned_to ID and its display value and put them on the form varname=item.getAttribute("name"); var name_label =item.getAttribute("name_label"); if(name_label &&name){ g_form.setValue('assigned_to',name, name_label);} else{ g_form.setValue('assigned_to','','');} // Get the assignment_group ID and its display value and put then on the form var group =item.getAttribute("group"); var group_label =item.getAttribute("group_label"); if(group_label && group){ g_form.setValue('assignment_group', group, group_label);} else{ g_form.setValue('assignment_group','','');}}} - Macro d’interface utilisateur d’approbation personnalisée
- Pour plus d’informations sur la création d’une macro d’interface utilisateur d’approbation personnalisée, reportez-vous à la section Macros d'interface utilisateur.