How to get value of child_incident from client script on incident form

patrykgryze
Tera Contributor

Hi, here is my script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    // get info from form
    var oldState = oldValue;
    var newState = newValue;
    var currentIncident = g_form.getValue('number');
	var childrenCount = g_form.getReference('child_incidents'); // error undefined :(

	// alert(count);

    if (newState == 6 && childrenCount > 0) {

        // https://davidmac.pro/posts/2022-02-08-glidemodal/
        var gm = new GlideModal("glide_prompt", true, 500);

        gm.setTitle(currentIncident + " is a parent incident!");
        gm.setPreference("title", "Enter yes if you would like to set " + currentIncident + " as resolved.\n ");
        gm.setPreference("onPromptComplete", function(value) {

            // if user NOT enter yes 
            if (value.toUpperCase() == "YES") {
                // show alert
                // g_form.clearMessages();
                g_form.showFieldMsg("state", currentIncident + " set as resolved!", "info", false);
            } else {
                //show alert
                g_form.setValue('state', oldState); // set state as previous state
                g_form.showErrorBox("state", currentIncident + " not set as resolved!", false);
            }
        });

        //window cancelled
        gm.setPreference("onPromptCancel", function(value) {
            g_form.showErrorBox('state', currentIncident + " not set as resolved!", false);
        });

        gm.render();

    }

}


My form does not have child_incident directly on the form.  I do not want it on my form.

My form is a default form. 

I would love not to use GlideRecord.

1 ACCEPTED SOLUTION

Viraj Hudlikar
Tera Sage

Hello parrykgryze,

As per your script g_form.getReference("child_incidents"); wont work use instead g_form.getValue("child_incidents"); as the field type is an integer.
About the field not getting on the form it will not fetch value to you from the client script. 
Workaround - Get the field on form in default view then create a UI Policy on the inc table and hide the child_incident field.

View solution in original post

2 REPLIES 2

Viraj Hudlikar
Tera Sage

Hello parrykgryze,

As per your script g_form.getReference("child_incidents"); wont work use instead g_form.getValue("child_incidents"); as the field type is an integer.
About the field not getting on the form it will not fetch value to you from the client script. 
Workaround - Get the field on form in default view then create a UI Policy on the inc table and hide the child_incident field.

Abhijit
Tera Expert

I would suggest you build display business rule and then load the value of child incidents by business rule script in g_scratchpad variable, then user g_scratchpad.child_incidents in your client script.

 

Display business rules gets value from record level and can be accessed in client script