CA Service Management

 View Only
Expand all | Collapse all

fetching properties of Change order before save

  • 1.  fetching properties of Change order before save

    Posted Nov 09, 2015 02:08 PM

    Hi,

     

    I would like to fetch  Change request values and labels of properties  to validate before save of Change Request.

     

    Example if a change request category have two properties.

     

    While creating a change order  I have to make a property mandatory(required) depends on the value provided on other Property.

     

    I have found two possible  options . First one is using pdm_list fetch the property list  and validate property values on save of a change request.

     

    but this option is bit tricky that inside java script function  pdm_list  is not working.

     

    second option is using spel customization below is the code that i am trying with below Code to fetch property value and Label


    @

    
    chg::zcheckprp(...)
    {
    string method,wc;
    method = "zcheckprp";
    int chgid;
    chgid = argv[3];
    wc= format("object_id = %d",chgid);
    logf(TRACE,"argv[3]=%d",chgid);
    logf(TRACE,"wc=%s",wc);
    uuid who;
    send_wait(0,top_object(), "call_attr", "cnt", "current_user_id");
    who=msg[0];
    send_wait(0, top_object(), "call_attr", "api", "get_list","prp",who,wc, -1);
    if (msg_error()) {
    logf(ERROR, "get_group_leader () failed: %s", msg[0]);
    }
    else
    {
    int count;
      object obList;
      count = msg[1];
      obList = msg[0];
    logf(ERROR,"count=%d",count); //Here the count is getting as 0 (zero)
      send_wait(0, top_object(), "call_attr", "api", "get_list_values", who, obList,0,count,0,"lable","value");
    if (msg_error()) {
    logf(ERROR, "get_group_leader () failed: %s", msg[0]);
      }
      else
      {
      int i;
      printf(argc);
      for (i=0;i<msg_length();i++) {
      logf(TRACE, "msg[%d]: '%s'", i, msg[i]);
        }
      }
    }
    }
    
    
    



    in the line 24 of above code the trace logging 'count' variable value as 0.

     

     

    any suggestions.

     

    Message was edited by: VENKAT V



  • 2.  Re: fetching properties of Change order before save

    Posted Nov 09, 2015 02:54 PM

    Hello, it should work as expected, I have tried the following test with bop_cmd and i getting expected results

     

    string method,wc; 
    method = "zcheckprp"; 
    int chgid; 
    chgid = 400606; 
    wc= format("object_id = %d",chgid); 
    logf(TRACE,"argv[3]=%d",chgid); 
    logf(TRACE,"wc=%s",wc); 
    uuid who; 
    send_wait(0,top_object(), "call_attr", "cnt", "current_user_id"); 
    who=msg[0]; 
    send_wait(0, top_object(), "call_attr", "api", "get_list","prp",who,wc, -1); 
    if (msg_error()) { 
    logf(ERROR, "get_group_leader () failed: %s", msg[0]); 

    else 

    int count; 
      object obList; 
      count = msg[1]; 
      obList = msg[0]; 
    printf("count=%d",count);


    }



  • 3.  Re: fetching properties of Change order before save

    Posted Nov 09, 2015 02:59 PM

    Can you please share the .mod file content.

     

    Thanks

     

    Sent from my iPhone



  • 4.  Re: fetching properties of Change order before save

    Posted Nov 09, 2015 03:09 PM

    I have no mod file i executed spel using bop_cmd command, this is why i hardcoded change id. I would guess that there is some problem with change id. If you run your spel script from the trigger on change object try to construct query in the following way:

    wc= format("object_id = %d",id);

     



  • 5.  Re: fetching properties of Change order before save

    Posted Nov 09, 2015 03:27 PM

    Hi Gutis,

    I will double check that

     

    I can see in log traces that query string  constructed as expected.

     

    I am suspecting trigger type might be the cause.

     

    I tried as follows

     

     

    MODIFY chg {POST_VALIDATE zcheckprp(id) 1113;};

     

    And PRE_VALIDATE as well , same as above.

     

    Thanks..

     

    Sent from my iPhone



  • 6.  Re: fetching properties of Change order before save

    Posted Nov 09, 2015 03:32 PM

    On wich event or condition do you wan't to trigger?



  • 7.  Re: fetching properties of Change order before save

    Posted Nov 10, 2015 10:29 AM

    Hi Gutis,

    This is scenario

     

    Change Category  'category-x' have to two properties

    First Property is a Drop-down (mandatory)  having two options (option-a and option-b)

    second property is a Check-box (optional)

     

    While Creating  or updating a Change order with 'category -x ' , if 'Property-1' value select as 'option-a ' Service Desk should force the user to select Check-box (property -2)  as must required .

     

    I tried to write a trigger first on chg object , checking for properties but it seems properties are not created by the time.

     

    secondly  triggered from prp object, in this case function is calling for two times since prp object is created for property one as well property two.

     

    How can we get all the related properties of change Order in run time (On or before save) in a single function call?

     

    Is there any other better approach to achieve this?

     

    Thanks,

    Venkat



  • 8.  Re: fetching properties of Change order before save

    Posted Nov 11, 2015 06:04 AM

    Hi, did you try to:

    1.  use POST_CI trigger, this trigger should be executed after object is checked in

    2. you can also can try to use while loop and  sleep() function to wait few times to see if properties will appear. Something similar to this

     

    int count,i;
    count = 0;
    object obList; 
    i=0;
    while (count = 0)
    {
     if (i == 10)
     {
     logf(ERROR, "Could not get Properties");
     return;
     } 
    send_wait(0, top_object(), "call_attr", "api", "get_list","prp",who,wc, -1);  
     if (msg_error()) {  
     logf(ERROR, "get_group_leader () failed: %s", msg[0]);  
     return;
     }
     else
     {  
     count = msg[1]; 
     obList = msg[0];  
     }
    sleep(1);
    i++;
    }
    


  • 9.  Re: fetching properties of Change order before save

     
    Posted Nov 16, 2015 06:36 PM

    Hi Venkat - We're you able to resolve your issue with the responses given? If so please mark Correct Answer as appropriate. Thanks! Chris



  • 10.  Re: fetching properties of Change order before save

    Posted Nov 09, 2015 11:31 PM

    my 2 cents:

    - i think that when you checking your chg, properties are not already created, even on post validate, so you need to trigger your macro on prp factory:

         MODIFY prp POST_VALIDATE zcheckprp() 1234 FILTER(object_type=='chg');

         // notice that id will be id of prp not chg

    - spel api methods are great, but generic sync_fetch is shorter and easier to read, why not to use them? (IMHO)



  • 11.  Re: fetching properties of Change order before save
    Best Answer

    Posted Nov 24, 2015 01:17 AM

    I strongly believe change orders and properties relation has been implemented/handled using cache memory till all the related objects got checked in an order.

    I have given a try using spel logic and java script both are serving to above requirement.

    attached related .spl and .js files.

     

    Thanks,

    Venkat

    Attachment(s)

    js
    emppropval.js   1 KB 1 version
    zip
    zcheckprp.spl.zip   1 KB 1 version