Customer Portal

Get Involved. Join the Conversation.

Topic

    Walter Kamp
    RNCPHP\MessageBase for custom messagebase record works only...Answered
    Topic posted May 10, 2017 by Walter KampSilver Medal: 2,000+ Points 
    614 Views, 21 Comments
    Title:
    RNCPHP\MessageBase for custom messagebase record works only in development
    Content:

    This line works perfectly fine in development mode:
    RNCPHP\MessageBase::fetch("CUSTOM_MSG_POPUP_TITLE_64")->Value;
    The code is in the getData() function of the controller.php of a widget.


    In staging and production we get this error:
    Fatal error: Uncaught exception 'RightNow\Connect\v1_3\ConnectAPIError' with message 'Invalid ID: No MessageBase record found with LookupName = '(1000288)'' in /cgi-bin/<site>.cfg/scripts/cp/generated/staging/staging_01/optimized/views/headers/ajax.php:19

    Any ideas?

     

    Version:
    CP 3.5.2, Service Cloud Nov'16

    Best Comment

    Pramod Vasudeva Murthy

    Could it be a bug? Is it same in Custom script using name? If it does that means there is some library in Custom script and not in Controller? Try putting this in model see if it makes a difference..

    ~VIP

    Comment

    • Walter Kamp

      Funny thing is that RNCPHP\MessageBase::fetch(1000288)->Value; works fine in staging and production...
      So, it seems to be an issue only when we use the messagebase key instead of the ID.

      Unfortunately, we have hundreds of custom messages, and the we can only use the key. Or we need to find a way to convert the key into ID in the controller php...

    • Pramod Vasudeva Murthy

      Could it be a bug? Is it same in Custom script using name? If it does that means there is some library in Custom script and not in Controller? Try putting this in model see if it makes a difference..

      ~VIP

    • Walter Kamp

      http://documentation.custhelp.com/euf/assets/devdocs/november2016/Connect_PHP/Content/Connect%20for%20PHP%20API/RightNow%20Connect%20Object%20Model/Core/MessageBase.html says we should add this line of code:

      // To use the predefined names for custom MessageBase items
      require_once( get_cfg_var( 'doc_root' ) . '/include/msgbase/msgbase.phph' );

      But that shows this error: Message: require_once(/cgi-bin/<site>.cfg/scripts/include/msgbase/msgbase.phph): failed to open stream: Operation not permitted

    • Pramod Vasudeva Murthy

      May be that library is not 'referable' in controller, pls add it in a custom model and see if it makes a difference..

      ~VIP

    • Bastiaan van der Kooij

      CUSTOM_MSG_POPUP_TITLE_64 is a constant and its value is 1000288, so if you loose the apostrophes you should be fine.  Alternatively you can just use getMessage(CUSTOM_MSG_POPUP_TITLE_64), which comes from \RightNow\Utils\Config::getMessage()

    • Walter Kamp

      Yes, 1000288 and CUSTOM_MSG_POPUP_TITLE_64 works fine, but we have to use "CUSTOM_MSG_POPUP_TITLE_64".
      Reason: "CUSTOM_MSG_POPUP_TITLE_" is fixed and 64 is added in PHP code. We use this to popup a message when you select a category, where we pass the ID of the category to the "CUSTOM_MSG_POPUP_TITLE_" part.
      Every category can have a different popup-text, -link, -title, -button text, -status etc... which is why we have lots of custom messagebase items.

    • Bastiaan van der Kooij

      I am not exactly sure what you're saying with that you have to use the apostropes, as I don't think that's actually in your code, it would not really be dynamic. I guess you're just trying to build up your constant name dynamically, which would be something like;

      $part1 = "CUSTOM_MSG_POPUP_TITLE_";
      $part2 = "64";
      echo getMessage(constant($part1.$part2));

    • Walter Kamp

      Yes, that's exactly what I'm trying to do.
      Your solution works fine... in development :-) but in staging I see this error:

      Fatal error: Uncaught exception 'Exception' with message 'Expected an integer for message slot ID, but got 'NULL' instead.' in /cgi-bin/<site>.cfg/scripts/cp/core/compatibility/optimized_includes.php:541 Stack trace: #0 /cgi-bin/<site>.cfg/scripts/cp/core/framework/3.5.2/CodeIgniter/system/CoreCodeIgniter.php(1467): RightNow\Api::msg_get_compat(NULL) #1 /cgi-bin/<site>.cfg/scripts/cp/core/framework/3.5.2/optimized_includes.php(11745): Rnow::getMessage(NULL) #2 /cgi-bin/<site>.cfg/scripts/cp/core/compatibility/optimized_includes.php(1804): RightNow\Utils\Config::getMessage(NULL, 'RNW') #3 /cgi-bin/<site>.cfg/scripts/cp/generated/staging/staging_01/optimized/views/headers/ajax.php(19): getMessage(NULL) #4 /cgi-bin/<site>.cfg/scripts/cp/core/framework/3.5.2/optimized_includes.php(2179): Custom\Widgets\PopupAjax->getData() #5 /cgi-bin/<site>.cfg/scripts/cp/core/framework/3.5.2/optimized_includes.php(2034): RightNow\Internal\Libraries\Widget\Base->loadDataArray() #6 /cgi-bin/<site>.cfg/scripts/cp/core/framework/3.5.2/optimized_include in /cgi-bin/<site>.cfg/scripts/cp/core/compatibility/optimized_includes.php on line 541

      But I found the solution: I moved all the code to a custom model, and that solves the issue. Seems to me that you can't use "-chars in widget controllers when retrieving the messagebase texts.


      Thanks for the help guys!

    • Bastiaan van der Kooij

      yeah the issue you're seeing is that the Constants are only defined in Production on what you're using so that would explain that building them dynamically is not working and they do not exist. As an alternative you can always use; 

      RNCPHP\MessageBase::find("LookupName = '".$messageName."'");
      
    • Suresh Thirukoti

      Great share Bastiaan!! this is bugging me for long time.....so is this documented somewhere? 

      ~Suresh

    • Walter Kamp

      Another way to bypass this BUG is to use ROQL:
      $roql_result = RNCPHP\ROQL::query( "SELECT Value AS Msg from MessageBase WHERE LookupName='".$id."'" )->next();
         

    • Bastiaan van der Kooij
      @Suresh: not sure if it's documented @Waltee: This is not a bug, just part of the optimization process for production. You would not want all message constants loaded uselessly. Find is a shorthand for a Roql query
    • Walter Kamp

      Well, if "RNCPHP\MessageBase::fetch("CUSTOM_MSG_POPUP_TITLE_64")->Value;" works fine in development, and does not work in production... it's a bug to me :-) But I'm glad we have a workaround now.

    • Dietrik

      We've also encountered this issue and according to Oracle:

      The development team has been able to provide a resolution to the issue reported and this is going to be included in February 2017 release, Service Pack 2.

    • Bastiaan van der Kooij

      @Walter, that's a fair point :)