General Technical Discussions for Service

Get Involved. Join the Conversation.


    Shreyas Pandhari
    Accessing and Setting Custom Field values in Custom Process
    Topic posted March 2, 2014 by Shreyas PandhariSilver Medal: 2,000+ Points, last edited March 2, 2014 
    611 Views, 3 Comments
    Accessing and Setting Custom Field values in Custom Process


    I am trying to access and set the custom field value in apply() as well as TestHarness() methods but process designer throws an error. I even tried with the way given in Oracle document but still no luck. 

    1. I tried with simple $object->CustomFields->c->field_name = 'xyz';

    2. I am getting no clear  understanding from the Snippet (below) in document

    Do we need to write metadata code for each custom field if I have n number of CFs? What is ocs_pid here?

    1. try{
    2. $inc = new RNCPHP\Incident;
    3. $md = $inc::getMetadata();
    4. $cf_type_name = $md->CustomFields->type_name;
    5. $md2 = $cf_type_name::getMetadata();
    6. $inc->CustomFields->c = new $md2->c->type_name;
    8. // must know the name 'ocs_pid' and
    9. // the data type that goes into it
    10. $inc->CustomFields->c->ocs_pid = "the field";
    12. // setting required fields for incident
    13. $cont = RNCPHP\Contact::fetch(123495);
    14. $inc->PrimaryContact = $cont;
    15. $inc->save();
    16. }
    18. catch (Exception $err ){
    19. echo $err->getMessage();
    20. }

    Any help to sort out this issue would be appreciated.







    • Yogesh J S

      Hi Shreyas,

      Please go through the following code in which, the apply function contains setting up  the value of a custom field(premium amount) of Opportunity object. Also in TestHarness(), I am  setting up the custom field(approval) value of Contact object.

      apply( $run_mode, $action, $obj, $n_cycles )
                                  $c_id = $obj->ID;
                                  $new_opportunity = new RNCPHP\Opportunity();
                                  $new_opportunity->PrimaryContact = new RNCPHP\OpportunityContact();
                                  $new_opportunity->PrimaryContact->Contact = RNCPHP\Contact::fetch($c_id);
                                  $new_opportunity->PrimaryContact->ContactRole = new RNCPHP\NamedIDLabel();
                                  $new_opportunity->PrimaryContact->ContactRole->ID = 2;
                                  $new_opportunity->CustomFields->c->premium_amount = 200;
                                  $new_opportunity->Name="Oppurtunity Created for ".$obj->Name->First." ".$obj->Name->Last;
                      catch (Exception $err)
                          echo $er;
          } // apply()

      class customfieldon_customprocess_TestHarness
          implements RNCPM\ObjectEventHandler_TestHarness
              static $con_invented;
              public static function setup()
                  $con = new RNCPHP\Contact;
                  $con->Name->First = "Steve";
                  $con->Name->Last = "Hook";
                  $con->CustomFields->c->approval = true;
                  static::$con_invented = $con;

      Hope this help.

    • Shreyas Pandhari

      Thanks Yogesh...It worked this time. I tried with the same way (described in my post) but it didn't work last time.



    • Dileep Mudadla

      Hi Shreyas,

      The 'ocs_pid' from that code snippet indicates just the name of the custom field which was already created (just an example) in the console and the commented line (// must know the name 'ocs_pid' and the data type that goes into it) indicates that we must be aware the names of the custome fields which were already created so that you can use in your Custom objects/CPM and instantiate/assign a value to that field as below:

      $inc->CustomFields->c->ocs_pid = "the field";

      In this case, the data type must have been a string (understand by seeing "the field").

      Hope this helps :-)


      Dileep Mudadla