Last active
March 10, 2023 18:49
-
-
Save cmcdevitt/89d58ff7d96f27669c65353b4be2049f to your computer and use it in GitHub Desktop.
UI Action List Field Type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| There is a Field Type called "UI Action List" which displays a Link in a Field. Clicking on the Link, calls a UI Action. | |
| The is a "complete" example on how to put this together. | |
| */ | |
| //Step One: Unhide the "UI Action List" Field Type | |
| var item = '355be32bbfa00100421cdc2ecf073929';//UI Action List / glide_action_list | |
| var gr = new GlideRecord('sys_glide_object'); | |
| gr.get(item); | |
| gr.setValue('visible',true); | |
| gr.update(); | |
| //Step Two: Create a Script Include to support a UI Action | |
| /* | |
| Name: sn_vul.DeferralSupportAJAX | |
| Application: Vulnerability Response (Whatever is approporate) | |
| Client callable: true | |
| Accessible from From: All Scopes | |
| Active: true | |
| Note ACL: You mane need a ACL Type: "client_callable_script_include" ACL if the instance is hardened | |
| */ | |
| var DeferralSupportAJAX = Class.create(); | |
| DeferralSupportAJAX.prototype = Object.extendsObject(global.AbstractAjaxProcessor, { | |
| getAssessmentInfo: function() { | |
| var instance = {}; | |
| var sysId = this.getParameter('sysparm_sys_id');//use 'rowSysId' in client script to get | |
| var ca = new GlideRecord('sn_vul_change_approval'); | |
| ca.get(sysId); | |
| if (ca) { | |
| instance.id = ca.assessment_instance; | |
| var ai = new GlideRecord('asmt_assessment_instance'); | |
| ai.get(ca.assessment_instance); | |
| instance.type = ai.metric_type; | |
| } else { | |
| return ''; | |
| } | |
| return instance.id + "," + instance.type; | |
| }, | |
| type: 'DeferralSupportAJAX' | |
| }); | |
| //Step Three: Create a UI Action | |
| /* | |
| Name: View Survey | |
| Table: Vulnerability State Change Approval [sn_vul_change_approval] | |
| Action name: show_survey | |
| Show update: true | |
| Client: true | |
| List v2 Compatable: true | |
| Form link: true | |
| Onclick: showResponse() | |
| */ | |
| function showResponse() { | |
| var ga = new GlideAjax('sn_vul.DeferralSupportAJAX'); | |
| ga.addParam('sysparm_name', 'getAssessmentInfo'); | |
| ga.addParam('sysparm_sys_id', rowSysId); | |
| ga.getXML(processIt); | |
| } | |
| function processIt(response) { //Callback function | |
| var answer = response.responseXML.documentElement.getAttribute("answer"); //Must use this exact line | |
| if (answer) { | |
| var items = answer.split(','); | |
| var url = 'assessment_take2.do?sysparm_assessable_sysid=' + items[0] + '&sysparm_assessable_type=' + items[1] + '&sysparm_reader_view=true'; | |
| var d = new GlideOverlay({ | |
| title: "User's Response", | |
| iframe: url, | |
| width: '80%', | |
| height: '100%', | |
| onAfterLoad: function() { | |
| var iframe = d.getIFrameElement(); | |
| setTimeout(function() { | |
| iframe.height = parseInt(iframe.height) + 1; | |
| }, 0); | |
| } | |
| }); | |
| d.render(); | |
| } | |
| } | |
| //Step Four: Create a new Field of Type: "UI Action List" | |
| /* | |
| Table: Vulnerability State Change Approval [sn_vul_change_approval] | |
| Column Lable:View Assessment | |
| Column name: u_view_assessment | |
| Active: true | |
| Read only: true | |
| Max length: 4000 | |
| Attributes: no_sort=true,slushbucket_ref_no_expand=true | |
| Default value: <the sys_id of the UI Action in Step Three> | |
| Note: This field will be blank for existing records. To backfill, add the sys_id of the UI Action to the old records | |
| */ | |
| //Optional: Backfill Script | |
| var custom_field = 'u_view_assessment';//Add your custom field name | |
| var ui_action = '71bdcde887ed65102d0b422e0ebb35bc';//Add the sys_id of your custom UI Action | |
| var gr = new GlideRecord('sn_vul_change_approval'); | |
| gr.addEncodedQuery('assessment_instance!=NULL^'+custom_field+'=NULL'); | |
| gr.query(); | |
| while(gr.next()){ | |
| gr.setValue(custom_field, ui_action); | |
| gr.update(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment