Clarity Service Management

get_properties 

12-10-2015 08:17 AM

SPEL API methods

get_properties

 

This method gets properties of the request, change or issue. Returns number of properties found and property list as the object. Most often it should be used in conjunction with get_list_values or dob_by_index method.

 

Definition:

get_properties( string) ;

string - persistent_id of an object that contains properties

 

 

working example:

object prp_list, prp;
  
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_properties", "cr:402125");  
 if (msg_error()) {  
  logf(ERROR, "get_failed %s",msg[0]);  
 }  
 else  
 {  
 int count,i;
 count = msg[1];
 prp_list = msg[0];
 for(i=0;i<count;i++) {
   send_wait(0, prp_list, "dob_by_index", "DEFAULT", i, i);
   prp = msg[0];
   logf(SIGNIFICANT,"Property %s value is %s",i,prp.value);
   printf("Property %s value is %s",i,prp.value);
  }
 }

Statistics
0 Favorited
0 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

05-11-2016 05:17 PM

Thanks cdtj

 

and yes i had to use that.. code is still in test and i plan modifying it but its giving me what i wanted to achieve..

 

below mod

 

OBJECT iss {

    TRIGGERS {

        POST_CI validateIssProperties(id,persistent_id) 301 FILTER(category=="SPSCOBVPM" && zreoccuring_issue != 1);

    } ;

} ;

 

spel

iss::validateIssProperties(...)

{

  duration timeout;

  timeout = 1;

  object prp_list, issprp, group_leader, iss_dob, iss_dob_result, g1;

  string prop_value;

  prop_value="";

  string iss_p_id;

  string wc;

  iss_p_id = argv[6];

  string event_name_prefix;

  event_name_prefix="Notify VES Leads";

  int flag;

  flag = 0;

 

  // First lets the properties attached and is selected value is Yes (Reoccouring Issue) then attach event to notify VES

 

  send_wait(0, top_object(), "call_attr", "api", "get_properties", iss_p_id);

  if (msg_error())

  {

   logf(ERROR, "get_failed %s",msg[0]);

  }

  else

  {

  prp_list = msg[0]; 

  send_wait(0, prp_list, "dob_by_index", "DEFAULT", 7, 7); 

  issprp = msg[0]; 

  //logf(SIGNIFICANT,"Property %s value is %s",7,issprp.value);  

 

  if (issprp.value == "Yes")

  {

  send_wait(0, top_object(), "get_co_group"); 

  if (msg_error())

  { 

  printf("Error'%s'", msg[0]); 

  return; 

  } 

  else

  { 

  group_leader = msg[0];

  send_wait(0, top_object(), "call_attr", "evt", "new_attached_event", group_leader, iss_p_id, event_name_prefix, timeout, now(), "SLA", 0, 0, "");

  if (msg_error())

  { 

  printf("Error %s",msg[0]); 

  } 

  send_wait(0, group_leader, "checkin"); 

  if (msg_error())

  { 

  printf("Error %s",msg[0]); 

  }

  flag = 1; // set the flag to 1 and based on it update the zreoccuring_issue field

  }

  }

 

  }

 

  // zreoccuring_issue field was created so we can replicate the Yes value. this field is not visible from the interface purpose of this field is have less complicated stored queries

 

  if (flag ==1)

  {

  sleep(1);

  send_wait(0, top_object(), "get_co_group");

  g1 = msg[0];

  send_wait(0, top_object(), "call_attr", "iss", "dob_by_id", 0, argv[3], NULL, NULL);

  iss_dob=msg[0];

  if (msg_error())

  {

   set_error(1);

   set_return_data(method + "dob_by_id:  " + msg[0]);

   return;

  }

  send_wait(0, g1, "checkout", iss_dob);

  if (msg_error())

  {

   set_error(1);

   set_return_data(method + "dob_by_id:  " + msg[0]);

   return;

  }

  iss_dob.zreoccuring_issue = 1;

  //send_wait(0, iss_dob, "call_attr", "zreoccuring_issue", "set_val", "1");

  send_wait(0, g1, "checkin"); 

  if (msg_error())

  {

   set_error(1);

   set_return_data(method + "dob_by_id:  " + msg[0]);

   return;

  }

  }

  return;

}

 

 

 

sorry for the nasty code

05-05-2016 10:34 AM

good to hear you have found working solution!

 

I would to suggest a little resource saving improvment, instead of checking data after each Issue update, you can create custom Property Rule with Yes/No question and call it for example "Yes/No (with trigger)",

update property rules in specified categories,

create mod file for iss_prp factory and specify filter like this: "FILTER( (value{}) && (validation_rule == <id_of_rule>) )".

 

sorry for boringness

05-05-2016 10:26 AM

also because I have to attach an event..

05-05-2016 10:13 AM

requirement is.. if a specific category issue is updated with a specific property drop down selected value is Yes I have to notify a group. update can be anytime before close (supposed to be fairly simple requirement)

so my plan is to trigger the spel code on any event for that given category check if the value is Yes. if yes attach an event with multiple notification.

I tried POST_VALIDATE before posting here but didn't help. POST_CI works.. since the issprp cache clears after issprp is checked in.

05-05-2016 02:19 AM

hi,

if you want to update Issue property maybe better to create MOD and SPEL file over iss_prp factory?

 

example:

iss_prp::z_my_script(...) {

  if ( (owning_iss.category == "SPSCOBVPM") && (value == "No") ) {

    send_wait(0, this, "call_attr", "value", "set_val", "Yes", "SURE_SET");

  } else {

    logf(SIGNIFICANT, "Nothing to change [%s] for [%s]", persistent_id, owning_iss);

  }

}

 

or using get_properties I think you need to use POST_CI because properties might not be checked in after issue's POST_VALIDATE,

on system layer algorithm could look:

- issue checkout;

- prp checkout;

- issue checkin;

- <SCRIPT ON ISSUE POST_VALIDATE>

- prp checkin.

 

just my 2 cents.

 

Regards,

cdtj

05-04-2016 04:06 PM

Try to change trigger to post_validate if this will not help to post_ci

05-04-2016 11:52 AM

So i am running into an issue and my code is below

 

MODIFY iss PRE_VALIDATE validateIssProperties() 301; ----> mod file

 

Spel

iss::validateIssProperties(...)

{

 

 

  if (category=="SPSCOBVPM")

  {

  object prp_list, issprp;

  string prop_value;

  prop_value="";

  send_wait(0, top_object(), "call_attr", "api", "get_properties", persistent_id);

  if (msg_error())

  {

   logf(ERROR, "get_failed %s",msg[0]);

  }

  else

  {

  int count,i;

  count = msg[1];

  prp_list = msg[0];

  send_wait(0, prp_list, "dob_by_index", "DEFAULT", 7, 7);

  issprp = msg[0];

  logf(SIGNIFICANT,"Property %s value is %s",7,issprp.value);

  }

  }

  else

  {

  // do nothing

  }

  return;

}

 

Reoccurring MisreadYes

 

thats the 8th property Reoccuring Misread -- its drop down (required field Yes/No)

 

issue is:

 

if i only update the property value to no and check stdlog it still shows Yes however after that if i update the any field on the form for same issue it shows No. any idea what am i doing wrong here

05-03-2016 04:30 PM

well its too hot i guess down here in south florida. ran query against prod db and code was in test

05-03-2016 03:31 PM

I would guess that this issue has no category defined or category does not contain propertirs

05-03-2016 02:17 PM

any idea why this is throwing error

 

object prp_list, issprp;

  string prop_value;

  prop_value="";

  send_wait(0, top_object(), "call_attr", "api", "get_properties", "iss:18221160"); -- this statement is failing with exception ..

 

spelsrvr             5276 ERROR        validateIssPropertie     9 get_failed Internal err with get_properties: NOT FOUND

 

 

SDM 14.1

12-10-2015 09:17 AM

Thank you for sharing

12-10-2015 09:05 AM

Thx Giedrius, this code works great.

 

I will try to contribute with the scenario of usage of this function.

 

Scenario is following:

I need to create a Condition Macro where I must take an action based on the value of specific property field in  the request

 

I used it with small modification of the Giedrius function

 

string z_get_prop_value(int req_id, int prop_sequence)

{

object prp_list, prp;

string prop_value;

prop_value="";

send_wait(0, top_object(), "call_attr", "api", "get_properties", format("cr:%s", req_id));

if (msg_error())

{

  logf(ERROR, "get_failed %s",msg[0]);

}

else

{

  int count,i;

  count = msg[1];

  prp_list = msg[0];

  for(i=0;i<count;i++)

  {

    send_wait(0, prp_list, "dob_by_index", "DEFAULT", i, i);

    prp = msg[0];

    if(prp.sequence==prop_sequence)

  {

   prop_value=prp.value;

  }

   }

 

}

return prop_value;

}

 

 

Then I have create a Condition Macro that use this function as a source for the value to compare

 

 

string prop_value;

prop_value = z_get_prop_value(cr.id, 10);

if ( upcase(prop_value) == "Value1" )

set_return_data(TRUE);

if ( upcase(prop_value) == "Value2" )

set_return_data(FALSE);

return;

 

 

so based on value of the property with sequence 10 you can perform action you need

 

Hope it will help someone :-)

Related Entries and Links

No Related Resource entered.