The useage of g_form.removeOption()

Supreeth R2
Kilo Contributor

Hello,

I have a requirement to hide a choice value 'Preview' from a 'category' field on the incident form for newly creating tickets without affecting the older tickets that is already being created in the system. I tried using g_form.removeOption() in the UI policy as well as in Client script but no luck.

Could anyone help me achieve this, please ?

 

Many Thanks,

Supreeth R

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Could you share your full code? Have you also verified that the UI Policy or Client Script is being executed at all?

Something like below should already work for UI Policy script. Though, also depending on your conditions.

function onCondition() {

	g_form.removeOption('category', 'network');
	
}

(field category, choice value network)

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

4 REPLIES 4

Brian Lancaster
Tera Sage

Is the Preview category not going to be used anymore of do you just want them not to be able to create tickets with that category anymore?

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Could you share your full code? Have you also verified that the UI Policy or Client Script is being executed at all?

Something like below should already work for UI Policy script. Though, also depending on your conditions.

function onCondition() {

	g_form.removeOption('category', 'network');
	
}

(field category, choice value network)

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hello Mark,

 

Below is the code what I've used. However, I know this isn't really a proper logic.

 

Client script:

 

function onLoad() {
    
 var ga = new GlideAjax('Remove_option');
    ga.addParam('sysparm_name', 'removeChoiceValue');
    ga.addParam('sysparm_openedat', g_form.getValue('opened_at'));
    ga.getXML(UserInfo);
    //var customer = g_form.getReference('u_customer', setLocation);
}

function UserInfo(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    if (answer >= '0')
        {
        
        g_form.removeOption('category', 'inquiry');
           
        
        }
}

----------------------------------------------------------------------------------------

 

Script Include:

 

var Remove_option = Class.create();
Remove_option.prototype = Object.extendsObject(AbstractAjaxProcessor, {
removeChoiceValue: function()
    {
        gs.log ('Remove option test1');
    var inc = new GlideRecord('incident');
        inc.query();
        while (inc.next())
            {
            gs.log ('Remove option test2');
var d1 = new GlideDateTime();
 var str = d1.toString();
 var d2 = str.split(" ");
 var d3 = d2[0];
 gs.log("currentDay is: "+d3);
 var d4 = this.getParameter('sysparm_openedat');
 var str1 = d4.toString();
 var d5 = str1.split(' ');
 var d6 = d5[0];
 gs.log("Incident created on: "+d6);
 var dif = gs.dateDiff(d3,d6,false);
 var diff = dif.split(' ',2);
 var diff1 = diff[0];
 diff2 = parseInt(diff1);
 gs.log("actual difference 1: "+diff2);
 gs.log("difference between days are "+dif);
    return diff2;
    }
    }
    
});

 

 

 

Okay, so have you verfied the onLoad Client Script is executed at all? Maybe it's already the UI Type field on the Catalog Client Script. Have you tried if the GlideAjax is performed okay, is it executed, does it give you the result you expect? Have you verified the log statements in your Script Include? Is the If statement in the function UserInfo reached?

My guess: your issue isn't the g_form.removeOption.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn