CA Service Management

Expand all | Collapse all

Automatically fill a field on detail_cr

Jump to Best Answer
  • 1.  Automatically fill a field on detail_cr

    Posted 01-03-2019 10:35 PM
    Good night people.
    I'm trying to make a customization that makes it possible to fill in the "Responsible site" (Local responsavel) field based on the information that was filled in the "Assignee" (Responsável) field.
    The information I want to put in the "Responsible site" (Local responsavel) field is part of the attributes of the Assignee:
    Any suggestions on how to do this customization?


  • 2.  Re: Automatically fill a field on detail_cr

    Posted 01-04-2019 03:04 PM

    Easiest way is to create a new trigger with a mod file and on "insert and update" copy info from assignee to ticket.

     

    Let me know if you need help. You may want to search the community before there is plainty of examples.



  • 3.  Re: Automatically fill a field on detail_cr

    Posted 01-07-2019 08:39 AM

    hi,


    not really nice neither heavily tested, but it seems to work (if you want it while you are in "edit" mode):

     

    add one more function to blur event of assignee field:

    <PDM_MACRO name=dtlLookup hdr="Assignee" attr=assignee evt="onBlur=\\\"detailSyncEditForms(this);onChgAss()\\\"">

     

    place this in javascript area of detail_pr.htmpl:

    function onChgAss() {
       AsyncAjaxCall(cfgCgi + "?SID=" + cfgSID + "+FID=" + cfgFID + "+numAutosuggestRecords=1+common_name=location+OP=SEARCH+FACTORY=cnt+QBE.EQ.id=" + document.main_form.elements["SET.assignee"].value, getSetCB);
    }

    function getSetCB(val) {
       window.async_set = eval(val.responseText)[0].value;
       AsyncAjaxCall(cfgCgi + "?SID=" + cfgSID + "+FID=" + cfgFID + "+numAutosuggestRecords=1+common_name=name+OP=SEARCH+FACTORY=loc+QBE.EQ.id=" + window.async_set, getKeyCB);
    }

    function getKeyCB(val) {
       // alert(eval(val.responseText)[0].value + " = " + window.async_set);
       document.main_form.elements["SET.zloc"].value = window.async_set;
       document.main_form.elements["KEY.zloc"].value = eval(val.responseText)[0].value;
    }

     

    regards, pacy



  • 4.  Re: Automatically fill a field on detail_cr

    Posted 01-11-2019 03:03 PM

    Hi pacy99 

     

    I applied a different solution, but I liked your tip. I'll test soon. I will soon put my solution to the case.

     

    regards, ClaudioGermano



  • 5.  Re: Automatically fill a field on detail_cr
    Best Answer

    Posted 01-17-2019 08:00 PM

    Hey guys,

     

    I managed to come up with a solution that may not be the most "elegant". I did based on a function that exists on CI forms. There is a specific function to update the manufacturer when the CI model changes. The functions are in the forms "nr_inv_tab.htmpl" and "nr_ops.js".

     

    It went something like this:

     

    In this first part of the code I declare the ID of the field "orig_user_admin_org" that is in the form "detail_cr" and I look for the attributes of that one through a URL and it returns as callback the name of the location of my "orig_user_admin_org".

     

     

    var zcurrCustID = "";
    function zorgChanged(form_name, base_name, lname, fname, mname, cntID, caller_type) {

        var IDorg = document.main_form.elements["SET.orig_user_admin_org"].value;
        //alert(IDorg); //newly selected orig_user_admin_org UUID
        var zFID = document.forms["main_form"].elements["FID"].value;
        var zSID = document.forms["main_form"].elements["SID"].value;
        var zorgID = document.main_form.elements["SET.orig_user_admin_org"].value;

        if (zcurrCustID == zorgID)
            return zcurrCustID = IDorg;
        //alert(zorgID);
        var url;
        if (ahdframe.currentAction == 0)
        {
            set_action_in_progress(ACTN_AUTOFILL);
        }
        url = cfgCgi + "?SID=" + zSID + "+FID=" + zFID +
            "+OP=SEARCH+FACTORY=org" +
            "+KEEP.domset_name=RLIST_STATIC" +
            "+QBE.EQ.id=" + escape(zorgID) +
            "+KEEP.backfill_attr=location.name" +
            "+HTMPL=javascript:parent.ahdframe.z_name_Location_Callback";
        display_new_page(url, ahdframeset.workframe);
        if (ahdframe.currentAction == 0)
        {
            set_action_in_progress(ACTN_AUTOFILL);
        }
    }

     

    In the previous function it calls the next function that will define where I will insert my CALLBACK and call again the URL to have as CALLBACK the ID of the "location". I did this to be able to preview the "KEY.zlocation" and the "SET.zlocation".

     

    function z_name_Location_Callback(persid, value, rel_attr_val) {
       
        set_action_in_progress(0);

        // Definir o campo que receberá o valor do callback
        var e = document.main_form.elements["KEY.zlocation"];

        e.value = value;
        // Chamar o proximo atributo que deseja buscar
        var zFID = document.forms["main_form"].elements["FID"].value;
        var zSID = document.forms["main_form"].elements["SID"].value;

        var url;
        if (ahdframe.currentAction == 0)
        {
            set_action_in_progress(ACTN_AUTOFILL);
        }
        url = cfgCgi + "?SID=" + zSID + "+FID=" + zFID +
            "+OP=SEARCH+FACTORY=org" +
            "+KEEP.domset_name=RLIST_STATIC" +
            "+QBE.EQ.id=" + escape(rel_attr_val) +
            "+KEEP.backfill_attr=location" +
            "+HTMPL=javascript:parent.ahdframe.z_id_Location_Callback";
        display_new_page(url, ahdframeset.workframe);
        if (ahdframe.currentAction == 0)
        {
            set_action_in_progress(ACTN_AUTOFILL);
        }
    }

     

    Here I conclude by inserting the CALLBACK of the last return in "SET.zlocation"

     

    function z_id_Location_Callback(persid, value, rel_attr_val) {

        set_action_in_progress(0);

        var e = document.main_form.elements["SET.zlocation"];

        e.value = value;

    }

     

    I realized that using this function it is not possible to return several information with a single "query" being necessary to chain several functions and in each of them to bring different information.