CA Service Management

 View Only
Expand all | Collapse all

Spel Attachments : get related request

  • 1.  Spel Attachments : get related request

    Posted Apr 07, 2016 10:44 AM

    Hello,

     

    I'm desperately trying to get the id of related request of an attachment.

    I tried several method, like getting "requests.cr", or like this :

     

    string _id, crPersid, whereClause;

        _id = (string)argv[3];

        whereClause = format("attmnt =%s",_id);

      

         send_wait(0, top_object(), "call_attr", "api", "get_lrel_values", "lrel_attachments_requests", whereClause,"cr");

    //   send_wait(0, top_object(), "call_attr", "lrel_attachments_requests", "val_by_key", "attmnt", _id, 1, "cr");

     

        if (msg_error()) {

            logf(ERROR, "Erreur lors de la récupération de l'incident lié la PJ '%s': '%s'", _id, msg[0]);

        } else {

            crPersid = msg[0];

            logf (SIGNIFICANT, "ATTMNT replication for request = %s", crPersid);

        }

     

    And the 2 send_wait ethod are not working.

     

    Every idea is welcomed !

     

    Thanks in advance.

     

    Chris.



  • 2.  Re: Spel Attachments : get related request

    Posted Apr 07, 2016 10:57 AM

    Hello,

    method val_by_key will work only if you have single attachment on request,

    you can get it in this way:

    object zobj;
    send_wait(0, top_object(), "call_attr", "lrel_attachments_requests", "sync_fetch", "STATIC", format("attmnt = %d", (int)_id),  -1, 0); // make sure that attachment id is INT
    if (!msg_error()) {
      send_wait(0, msg[0], "dob_by_index", "DEFAULT", 0, 0);
      zobj = msg[0];
      logf(SIGNIFICANT, "Attachemnt : %s, %s : %s", zobj.attmnt, zobj.cr.type.sym, zobj.cr.ref_num);
    }
    
    

     

    Regards,

    cdtj



  • 3.  Re: Spel Attachments : get related request

    Posted Apr 07, 2016 11:20 AM

    Thank you.

     

    I thought that it will be ok, because the attachment is related to one request...

     

    I tried your method, but i get errors that I don't understand (I'm not very familiar with spel coding...) :

    Spell interp failed at attmnt::zattmnt_send_maps (...) gipsi_attmnt.spl:18: Math argument type mismatch // Line 18 corresponding to zobj = msg[0];

    Spell interp failed at gipsi_attmnt.spl:19:attmnt::zattmnt_send_maps: No object for member variable attmnt // Line 19 corresponding to logf(SIGNIFICANT, "Attachemnt : %s, %s : %s", zobj.attmnt, zobj.cr.type.sym, zobj.cr.ref_num);

    And the content of msg is :

    msg[0]: 'NOT FOUND'

    msg[1]: '0'

     

    Could you please explain me this "sync_fetch" method and its arguments ?

     

    Chris.



  • 4.  Re: Spel Attachments : get related request

    Posted Apr 08, 2016 04:00 AM

    Are you sure that you pass correct attmnt id?

    send_wait(0, 
    top_object(), 
    "call_attr", 
    "lrel_attachments_requests",     // affected factory
    "sync_fetch",      // 
    "STATIC",      // domset, could affect on sorting order
    format("attmnt = %d", (int)_id),    // regular whereclause
    -1, 
    0);
    

     

    could you attach spl function and place where it called (mod file or other spl)?



  • 5.  Re: Spel Attachments : get related request

    Posted Apr 08, 2016 04:20 AM

    Hello,

     

    Yes, I'm sure. I get it through a mod file, so the trigger is called in post validation of attachment.

     

    Here's the .mod :

    OBJECT attmnt {
        TRIGGERS {
            POST_VALIDATE zattmnt_send_maps(id,created_by) 666 FILTER( EVENT("INSERT") );
        };
    } ;
    

    And the .spl :

    attmnt::zattmnt_send_maps(...)
    {
        if(substr(created_by.userid,0,5)== "GIPSI")
            return;
       
        string method;
        int _id;
        method = "zattmnt_send_maps";
        _id = (int)argv[3];
    
        object zobj; 
        send_wait(0, top_object(), "call_attr", "lrel_attachments_requests", "sync_fetch", "STATIC", format("attmnt = %d", _id),  -1, 0); // make sure that attachment id is INT 
        if (!msg_error()) { 
          send_wait(0, msg[0], "dob_by_index", "DEFAULT", 0, 0); 
          zobj = msg[0]; 
          logf(SIGNIFICANT, "Attachment : %s, %s : %s", zobj.attmnt, zobj.cr.type.sym, zobj.cr.ref_num); 
        } 
        else {
            logf(ERROR,"%s", msg[0]);     
            return;
        }
       
        string cmdlineprocess;
        string parameters;
        string serveur;
        string proc_path;
    
        serveur = getenv("NX_WS_SERVER");
        proc_path = getenv("NX_PROC_PATH");
    
        parameters = format("-serveur %s -port %s -action %s -attmnt_id %s", serveur, "8443", "ATTMNT", _id);
    
        // Lancement du batch d'appel du Web Service
        cmdlineprocess = proc_path +" "+parameters;
      
        logf (SIGNIFICANT, "%s - Calling command... [%s]", method,cmdlineprocess);
        send(bpnotify_object(), "create_process", cmdlineprocess);
        logf (SIGNIFICANT, "%s - command executed...", method);
        if (msg_error()) {
          logf (ERROR, "%s - Error while calling cmd line object: %s", method, msg[0]);
          return;
        }
        logf(SIGNIFICANT, "-- %s completed!", method);
    }
    

     

    Chris.



  • 6.  Re: Spel Attachments : get related request
    Best Answer

    Posted Apr 08, 2016 05:08 AM

    I think that when you insert an attachment, it's not exist in LREL table.

     

    You can try to check lrel_attachments_requests in your script:

    OBJECT lrel_attachments_requests  {  
        TRIGGERS {  
            POST_VALIDATE zattmnt_send_maps(attmnt, cr) 666 FILTER( EVENT("INSERT") );
        };  
    } ; 
    

     

    SPL file will be short:

    string cr_persid;
    int attmnt_id;
    attmnt_id = argv[3];
    cr_persid = argv[6];
    logf(SIGNIFICANT, "cr is %s, attmnt is %d", cr_persid, attmnt_id);
    


  • 7.  Re: Spel Attachments : get related request

    Posted Apr 08, 2016 05:26 AM

    I have not even thought about that yet so simple solution, and that works perfectly

     

    Thank you so much !

     

    Chris.



  • 8.  Re: Spel Attachments : get related request

    Posted Apr 08, 2016 05:33 AM

    You are welcome!

     

    Could you explain, what this line do?

    send(bpnotify_object(), "create_process", cmdlineprocess); 

    I haven't seen any mention about that object/method before.



  • 9.  Re: Spel Attachments : get related request

    Posted Apr 08, 2016 06:19 AM

    It's a function which can start any executable, and wait for its termination.

    I use it to start automatically a powershell script with all needed arguments.

    The third argument is the absolute path to the script, but I can't explain it more, I've just copied it from another CA customization.



  • 10.  Re: Spel Attachments : get related request

    Posted Apr 08, 2016 06:47 AM

    Thanks! I have checked it and it seems that it's functionality is equal to exec(string); function.

     

    send(bpnotify_object(), "create_process", "ping localhost");

    and

    exec("ping localhost");

    Displays same result in stdlog file.



  • 11.  Re: Spel Attachments : get related request

    Posted Apr 08, 2016 06:52 AM

    Maybe the difference is that the send function created a seperate process, while the exec use the same process that SD, I don't know.

    I will ask a CA consultant when I'll see him.