Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Mohana Gopal Selvam
    How to get the custom Yes/No field value using CPHPAnswered
    Topic posted November 30, 2015 by Mohana Gopal SelvamSilver Crown: 22,500+ Points 
    863 Views, 22 Comments
    Title:
    How to get the custom Yes/No field value using CPHP
    Content:

    Hi Gurus,

    We have created the custom Yes/No field in Incident object. We have to fetch the value in CPM. I have tried the following codes. But it returns null value for all variables. Please let me know the correct code. 

         $sendsms = $incident->CustomFields->c->send_sms;
         $sendsmslookupname = $incident->CustomFields->c->send_sms->LookupName;
         $sendsmsvalue = $incident->CustomFields->c->send_sms->Value;
         $sendsmslookuname = $incident->CustomFields->c->send_sms->Name;
         print($sendsms);
         print($sendsmslookupname);     
         print($sendsmslookvalue);
         print($sendsmsname);

    Thanks,

    Mohan

    Best Comment

    Barrilito van Dijk

    Hi Mohana,

    I think your first option is spot on ($sendsms = $incident->CustomFields->c->send_sms), that should be working.

    @Allan: what was the defect precisely about? In what release is it and will it be patched?

    It is good if there are workarounds for things and it is certainly appreciated to see people get involved to give some hints for a workaround, but things like this should have no workaround, this is such basic stuff, if that comes into a defect status I feel there should be some prio on fixing it asap in some kind of patch. I think Mohana prefers to spend time on making nice OSC solutions instead of re-inventing CPHP again to do a basic querywink

     

     

    Comment

    • Allan Schrum

      There was a defect associated with this that has been fixed. The work around is to either use ROQL to get the information (using ROQL::query(), not ROQL::queryObject()), or to use the revert() method on the incident and then re-fetch it:

      $inc_id = $incident->ID;
      $incident->revert();
      $incident = RNCPHP\Incident::fetch( $inc_id );

      Regards,

      -Allan

    • Kesava Kumar

      Hi,

      Try this below code and you can get custom Yes/No field values as 1(yes) or 0(No)

      $sendsmsID=$incident->CustomFields->c->send_sms->ID;

      Thanks

      kesava

    • Mohana Gopal Selvam

      Hi Allan,

      The below code is not working even I tried with Revert() function.

           $inc = RNCPHP\Incident::fetch(1750);
           $inc_id = $inc->ID;
           $inc->revert();
           $inc = RNCPHP\Incident::fetch( $inc_id );
           $sendsmsname1 = $inc->CustomFields->c->send_sms->name;
           $sendsmsid1 = $inc->CustomFields->c->send_sms->ID;
           print("\nName".$sendsmsname1);
           print("\nId".$sendsmsid1);

      @Kesava,

      When I tried with ID, it returns the value. I want to fetch the name directly.

      Thanks,

      Mohan

    • Barrilito van Dijk

      Hi Mohana,

      I think your first option is spot on ($sendsms = $incident->CustomFields->c->send_sms), that should be working.

      @Allan: what was the defect precisely about? In what release is it and will it be patched?

      It is good if there are workarounds for things and it is certainly appreciated to see people get involved to give some hints for a workaround, but things like this should have no workaround, this is such basic stuff, if that comes into a defect status I feel there should be some prio on fixing it asap in some kind of patch. I think Mohana prefers to spend time on making nice OSC solutions instead of re-inventing CPHP again to do a basic querywink

       

       

    • Mohana Gopal Selvam

      Hi BvD,

      As you said, the below code only working.

      $sendsms = $inc->CustomFields->c->send_sms; 

      @Kesava,

      The below code is not working.

      $sendsmsid = $inc->CustomFields->c->send_sms->ID;

      Thanks,

      Mohan

       

    • Allan Schrum

      If send_sms is a NamedID then $inc->CustomFields->c->send_sms->LookupName will be the "string" equivalent of the value. You can always:

      $md = $inc->CustomFields->c->send_sms->getMetadata();
      var_export( $md );

      to check to make sure it is what you think it is (from Connect PHP's viewpoint).

      My workaround is the posted work around for this topic although the "revert()" call was not previously mentioned. The "revert()" ensures that the object is stale and will be properly fetch()'d.

      @BvD: This was found and fixed in our 14.11 release of our product. This has been service packed as far back as 13.11SP5 (thus including 14.2SP4, 14.5SP2, and 14.8SP2).

      Regards,

      -Allan

    • Barrilito van Dijk

      @Allan: thank you for the details, that is appreciated.

      @Mohana: is your question answered? If so, could you mark any question as best answer please so that people can see the question is being answered.

      Thanks!

    • Mohana Gopal Selvam

      Hi BvD,

      When I set No for my Yes/No field, it returns Null value. If I set Yes then only it returns 1. Its strange. Do you have any idea?

      $sendsms = $incident->CustomFields->c->send_sms;

      Thanks,

      Mohan

       

    • Barrilito van Dijk

      Hi Mohana,

      Where does it return "null"? Try to do a var_dump() of a variable where you store the value to see the actual result in the page.

    • Mohana Gopal Selvam

      Hi BvD,

      I have got the empty/null value in Test Harness for the 'No' value, when I use the below code. I received 1 for the 'Yes' value. 

      $sendsms = $inc->CustomFields->c->send_sms;

      print($sendsms);

      If I use var_dump it returns bool(false);

      Thanks,

      Mohan

    • Barrilito van Dijk

      Hi Mohan,

      If the var_dump gives back false, does it give "true" for the "yes" or a "1" ?

      Anyway, if you check on "1" or "true" as "yes" all other options are "no" wink

    • Mohana Gopal Selvam

      Hi BvD,

      var_dump gives bool(true) for "yes". But I have to capture the 'No' value.

      :-(

      Is there any other workaround for capturing the No value. I have created another custom field Customer Satisfaction (cust_satisfacation). If the customer not satisfied, I have to do some business logic.

      Thanks,

      Mohan

       

    • Barrilito van Dijk

      Hi Mohan,

      If no gives back false and yes gives back true, I don't see any problem.

      If you need to do something on no you can say:

      if ($sendsms==false) {

        // do the things for when NO

      }

      else {

        // do the things for when YES

      }

    • Mohana Gopal Selvam

      Hi BvD,

      var_dump only returns bool(false) when I use the below code

      var_dump($sendsms);

      But when I print the $sendsms it returns null/empty value. I could not use this variable for my condition since it returns false for both No and Null. Is there any workaround apart from ROQL?

      Thanks,

      Mohan

    • Barrilito van Dijk

      Hi Mohan,

      Ok. Sorry you are not making progress.

      I don't know further how to help out, perhaps someone else can help you with this.

      Regards,