Agent Desktop

Get Involved. Join the Conversation.

Topic

    Rasheed Ahamed
    Show selected product, category level in Message TemplateAnswered
    Topic posted May 27, 2019 by Rasheed AhamedGold Medal: 3,500+ Points, last edited May 27, 2019 
    76 Views, 10 Comments
    Title:
    Show selected product, category level in Message Template
    Summary:
    Proper Display of chosen Product Categories in Message Template
    Content:

    Hi,

    In Message Templates I have selected 6 levels of Products and Categories to reflect in e-mail to the user for the selected product/category.
    I have used " > " as intermediate symbol to mention the levels. Issue arises when there are lesser levels of products/categories selected. Those " > " are looking weird at the end. How to get rid of them and display properly only/till the selected products/categories.
    PFA.

    Regards,
    Rasheed

    Image:

    Best Comment

    Rasheed Ahamed

    No Sebastiaan, I have neither checked the Execute Asynchronously checkbox nor the Can Suppress checkbox.
    I can share my CPM codebase here, in case if you wanted to try on this use case. Kindly let me know the results if you tried. 
    Note: If in case you/anyone wanted to try this. Create two custom text fields with this column names selected_product_level and selected_category_level.

     

    <?php
    /*
    * CPMObjectEventHandler: incident_handler
    * Package: RN
    * Objects: Incident
    * Actions: Create, Update
    * Version: 1.3
    * Purpose: On Save, System stores the product category hierarchy in 2 CustomFields which will be used in Message Template.
    * Author : Rasheed Ahamed 
    */
     
    // This object procedure binds to v1_3 of the Connect PHP API
    use \RightNow\Connect\v1_3 as RNCPHP;
    // This object procedure binds to the v1 interface of the process
    // designer
    use \RightNow\CPM\v1 as RNCPM;
     
    /**
    * An Object Event Handler must provide two classes:
    * - One with the same name as the CPMObjectEventHandler tag
    * above that implements the ObjectEventHandler interface.
    * - And one of the same name with a "_TestHarness" suffix
    * that implements the ObjectEventHandler_TestHarness interface.
    *
    * Each method must have an implementation.
    */
     
    class incident_handler implements RNCPM\ObjectEventHandler{
     
        public static function apply( $run_mode, $action, $obj, $n_cycles )
        {
            if($n_cycles>1) return false;
            try{                
                    $prodName = $obj->Product->LookupName;
                    $catName = $obj->Category->LookupName;
     
    echo "<pre>";
    $lastProdLevel = $obj->Product->LookupName;
    $numberOfProducts = count($obj->Product->ProductHierarchy);
    $productHierarchy = "";
    for($i=0; $i<$numberOfProducts; $i++)
    {
    $productHierarchy = $productHierarchy.$obj->Product->ProductHierarchy[$i]->LookupName;
    $productHierarchy = $productHierarchy." > ";
    }
    $productHierarchy = $productHierarchy.$lastProdLevel;
    print_r($productHierarchy);
    $obj->CustomFields->c->selected_product_level = $productHierarchy;
     
     
    echo "<pre>";
    $lastCatLevel = $obj->Category->LookupName;
    $numberOfCategories = count($obj->Category->CategoryHierarchy);
    $categoryHierarchy = "";
    for($i=0; $i<$numberOfCategories; $i++)
    {
    $categoryHierarchy = $categoryHierarchy.$obj->Category->CategoryHierarchy[$i]->LookupName;
    $categoryHierarchy = $categoryHierarchy." > ";
    }
    $categoryHierarchy = $categoryHierarchy.$lastCatLevel;
    print_r($categoryHierarchy);
    $obj->CustomFields->c->selected_category_level = $categoryHierarchy;
     
     
     
                    $obj->save();
                    echo "Incident ID : ".$obj->ID;
                    echo "Incident Product : ".$obj->CustomFields->c->selected_product_level;
    echo "Incident Category : ".$obj->CustomFields->c->selected_category_level;                
                }
                catch(Exception $err)
                {
                    print_r($err);
                }
            return;
        } // apply()
     
     
     
    /*
    The Test Harness
    */
     
     
    class incident_handler_TestHarness implements RNCPM\ObjectEventHandler_TestHarness
    {
        static $con_invented = NULL;
     
        public static function setup()
        {
            try{
                $incident = new RNCPHP\Incident(); 
                $incident->PrimaryContact = RNCPHP\Contact::fetch(31);
                $incident->Subject = "Incident Created By Test Harness Method";        
                $incident->Product =  RNCPHP\ServiceProduct::fetch(113);        
                $incident->Category = RNCPHP\ServiceCategory::fetch(32);
                //$incident->CustomFields->c->fault_type->ID = 755;
                $incident->save();
                // $inc->save(RNCPHP\RNObject::SuppressAll);
            }
            catch(Exception $err){
                echo $err;
            }
     
            static::$con_invented = $incident;
            return;
        }
     
        public static function fetchObject( $action, $object_type ){
            // Return the object that we
            // want to test with.
            // You could also return an array of objects
            // to test more than one variation of an object.$incident
            return(static::$con_invented);
        }
     
        public static function validate( $action, $object ){
        // Add one note.
        return true;
        }
     
        public static function cleanup(){
        // Destroy every object invented
        // by this test.
        // Not necessary since in test
        // mode and nothing is committed,
        // but good practice if only to
        // document the side effects of
        // this test.
        static::$con_invented->destroy().
        static::$con_invented = NULL;
        return;
        }
    }

    Comment

     

    • Sebastiaan Draaisma

      Hi Rasheed.

      This can not be removed in the message template and you are unable to use the different levels in a conditional section. A workaround would be the use of a custom field (text field) where you use a CPM to copy the selected level into this custom field. The custom field can than be used in your message template which would always show the selected level and not the entire path. If desired, you could also show the entire path but without the aditional empty > > >

      Let me know if you need assistance with your CPM.

      • Rasheed Ahamed

        Hi Sebastiaan,

        I created two custom text fields and wrote a CPM which will store the product and category hierarchy data in the respected fields on Incident Save. It is working fine, I previewed it in the Message Template and I tested it by adding those fields to the Workspace. But however in the e-mail, I got the product, category as empty values. I think it is because of the reason that e-mail is triggered first and then the CPM runs and sets the value so in the e-mail I'm getting the empty values. Kindly share your thoughts on any workaround in this case.

        Thanks,
        Rasheed.

    • Sebastiaan Draaisma

      Yes, that is possible. What you could do is use a business rule as the trigger for your CPM and place that one above the business rule responsible for the Send Receipt Email. This ways the custom field is populated before the question receipt gets send.

      • Rasheed Ahamed

        Hi Sebastiaan, 

        I have removed the event handler and triggered it from Business Rules and kept it in first place still I could not see the product category hierarchy in the email.
        PFA Rule Screenshot. Please let me know if there are changes required in the rule condition.

    • Sebastiaan Draaisma

      Yeah, looks right...
      How does the rule log look? Does it trigger in the correct sequence?

    • Sebastiaan Draaisma

      In that case I would rase an SR with Oracle to see if you found a bug. The rule log looks correct, CPM get's triggered first setting the custom field that is used in your message template which is triggered after the CPM. It should work as this is also how conditional sections work in a message template (value such as queue is set through a rule and then used in a conditional section to send the right content in a question receipt) so you may have found a bug.

    • Sebastiaan Draaisma

      One thing I forgot to ask is if you have checked the Execute Asynchronously box for your CPM. If so, this may delay the CPM which could explain an empty value in the message template.

      • Rasheed Ahamed

        No Sebastiaan, I have neither checked the Execute Asynchronously checkbox nor the Can Suppress checkbox.
        I can share my CPM codebase here, in case if you wanted to try on this use case. Kindly let me know the results if you tried. 
        Note: If in case you/anyone wanted to try this. Create two custom text fields with this column names selected_product_level and selected_category_level.

         

        <?php
        /*
        * CPMObjectEventHandler: incident_handler
        * Package: RN
        * Objects: Incident
        * Actions: Create, Update
        * Version: 1.3
        * Purpose: On Save, System stores the product category hierarchy in 2 CustomFields which will be used in Message Template.
        * Author : Rasheed Ahamed 
        */
         
        // This object procedure binds to v1_3 of the Connect PHP API
        use \RightNow\Connect\v1_3 as RNCPHP;
        // This object procedure binds to the v1 interface of the process
        // designer
        use \RightNow\CPM\v1 as RNCPM;
         
        /**
        * An Object Event Handler must provide two classes:
        * - One with the same name as the CPMObjectEventHandler tag
        * above that implements the ObjectEventHandler interface.
        * - And one of the same name with a "_TestHarness" suffix
        * that implements the ObjectEventHandler_TestHarness interface.
        *
        * Each method must have an implementation.
        */
         
        class incident_handler implements RNCPM\ObjectEventHandler{
         
            public static function apply( $run_mode, $action, $obj, $n_cycles )
            {
                if($n_cycles>1) return false;
                try{                
                        $prodName = $obj->Product->LookupName;
                        $catName = $obj->Category->LookupName;
         
        echo "<pre>";
        $lastProdLevel = $obj->Product->LookupName;
        $numberOfProducts = count($obj->Product->ProductHierarchy);
        $productHierarchy = "";
        for($i=0; $i<$numberOfProducts; $i++)
        {
        $productHierarchy = $productHierarchy.$obj->Product->ProductHierarchy[$i]->LookupName;
        $productHierarchy = $productHierarchy." > ";
        }
        $productHierarchy = $productHierarchy.$lastProdLevel;
        print_r($productHierarchy);
        $obj->CustomFields->c->selected_product_level = $productHierarchy;
         
         
        echo "<pre>";
        $lastCatLevel = $obj->Category->LookupName;
        $numberOfCategories = count($obj->Category->CategoryHierarchy);
        $categoryHierarchy = "";
        for($i=0; $i<$numberOfCategories; $i++)
        {
        $categoryHierarchy = $categoryHierarchy.$obj->Category->CategoryHierarchy[$i]->LookupName;
        $categoryHierarchy = $categoryHierarchy." > ";
        }
        $categoryHierarchy = $categoryHierarchy.$lastCatLevel;
        print_r($categoryHierarchy);
        $obj->CustomFields->c->selected_category_level = $categoryHierarchy;
         
         
         
                        $obj->save();
                        echo "Incident ID : ".$obj->ID;
                        echo "Incident Product : ".$obj->CustomFields->c->selected_product_level;
        echo "Incident Category : ".$obj->CustomFields->c->selected_category_level;                
                    }
                    catch(Exception $err)
                    {
                        print_r($err);
                    }
                return;
            } // apply()
         
         
         
        /*
        The Test Harness
        */
         
         
        class incident_handler_TestHarness implements RNCPM\ObjectEventHandler_TestHarness
        {
            static $con_invented = NULL;
         
            public static function setup()
            {
                try{
                    $incident = new RNCPHP\Incident(); 
                    $incident->PrimaryContact = RNCPHP\Contact::fetch(31);
                    $incident->Subject = "Incident Created By Test Harness Method";        
                    $incident->Product =  RNCPHP\ServiceProduct::fetch(113);        
                    $incident->Category = RNCPHP\ServiceCategory::fetch(32);
                    //$incident->CustomFields->c->fault_type->ID = 755;
                    $incident->save();
                    // $inc->save(RNCPHP\RNObject::SuppressAll);
                }
                catch(Exception $err){
                    echo $err;
                }
         
                static::$con_invented = $incident;
                return;
            }
         
            public static function fetchObject( $action, $object_type ){
                // Return the object that we
                // want to test with.
                // You could also return an array of objects
                // to test more than one variation of an object.$incident
                return(static::$con_invented);
            }
         
            public static function validate( $action, $object ){
            // Add one note.
            return true;
            }
         
            public static function cleanup(){
            // Destroy every object invented
            // by this test.
            // Not necessary since in test
            // mode and nothing is committed,
            // but good practice if only to
            // document the side effects of
            // this test.
            static::$con_invented->destroy().
            static::$con_invented = NULL;
            return;
            }
        }
    • Sebastiaan Draaisma

      I gave it a quick look but looks fine and I assume you tested the CPM that it writes the field and that it's just that it's empty in your message template right?

      If your CPM works which I believe it does since you wrote 'It is working fine', and the Async is disabled, I can only assume that this must be a bug since your CPM gets triggered before your message template. Raise an SR with Oracle to hear with them. I believe you have done everything correct. When raising an SR you can include the url to this topic so they can see what you have tested and that way you don't have to type that much in your SR :-)