Jump to content
iljas

SPEL: Parent -> Child - Outage update

Recommended Posts

Hello, 

i am a new SPEL  user and need your help. Idea is to update child outage_type (only if it's empty) from parent and only if parent is "Closed/Resolved"

From what i have right now is code to update(rewrite) child outage type on every change in pratent:

cr::z_copy_outage_type_from_parent(...) {
  string method;

  method = "cr::z_copy_outage_type_from_parent()";
  
  logf(SIGNIFICANT, "Start spel %s for ticket %s", method, this.ref_num);
  
  //save information about outage type from parent
  send_wait(0, this, "call_attr", "outage_type", "set_val", this.parent.outage_type, "SURE_SET" );

  logf(SIGNIFICANT, "Konec spel %s for ticket %s", method, this.ref_num);  
}

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

cr::z_copy_outage_type_to_children(...) {
    
  string method, wc;
  int c_count, i;
  object c_list, group_leader, c_dob;

  method = "cr::z_copy_outage_type_from_parent()";
  
  logf(SIGNIFICANT, "Start spel %s for ticket %s", method, this.ref_num);
 
    wc = format("parent = '%s'", this.persistent_id, this.outage_type); 
 
    send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "MLIST_STATIC", wc, -1,0);
    c_count = msg[1];
    c_list = msg[0];
    if (c_count > 0) {
    for(i = 0; i < c_count; i++) {
            send_wait(0, top_object(), "get_co_group");
            group_leader = msg[0];
 
      //load child ticket
            send_wait(0, c_list, "dob_by_index", "DEFAULT", i, i);
            c_dob = msg[0];
    
    
      //save outage_type info
      send_wait(0, group_leader, "checkout", c_dob);
      
      
            send_wait(0, c_dob, "call_attr", "outage_type", "set_val", this.outage_type, "SURE_SET" );
            send_wait(0, group_leader, "checkin");
    
        
    }
  } 
  logf(SIGNIFICANT, "End of spel %s for ticket %s", method, this.ref_num);  
}

 

I tried several costumizations but only thing that i got was errors 

 

Can you help me please?

 

Thank you and regards

 

Share this post


Link to post
Share on other sites

hi, your code should work, providing errors could help to figure out what's wrong.

I found only 1 error: wc = format("parent = '%s'", this.persistent_id, this.outage_type); // passing 2 arguments but receiving only 1.

ps: there is no need to write a lot of code with this "lib": https://github.com/cdtj/zspel, after installation the second method can look like:

cr::z_copy_outage_type_to_children(...) {
	string method, wc;
	method = "cr::z_copy_outage_type_from_parent()";

	logf(SIGNIFICANT, "start %s for ticket %s", method, ref_num);
	wc = format("parent = '%s'", persistent_id);
	z_upd_val("cr", wc, 1, 1, "outage_type", outage_type);

	logf(SIGNIFICANT, "end %s for ticket %s", method, ref_num);
}

ps2: there is no need to use "this" in context of this object. (eg: this.ref_num equals ref_num).

Share this post


Link to post
Share on other sites

Thank you for reply, 

 

i tried use your method but still have no success. 

Probably  because  i tried modify this line:  

z_upd_val("cr", wc, 1, 1, "outage_type", outage_type);

since i am realy green in this, i tried use send_wait method, but got errors like " Missing object to send to " or  unknown function. Can you help me?

And one more thing, since there is possibility that  TRIGGERS  can do harm to, these are that we used for previous functions:

 

POST_VALIDATE z_copy_outage_type_from_parent() 400004 FILTER(EVENT("INSERT UPDATE") && parent{});

POST_VALIDATE z_copy_outage_type_to_children() 400005 FILTER(EVENT("INSERT UPDATE") && outage_type{});

 

Are they ok for the function that i try to use?

 

Thank you for help and regards

Share this post


Link to post
Share on other sites

The whole code including triggers and logs could help (and don't forget to put them in <code> tag ;)).

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...