Support Article

Clipboard to JSON - properties with null values are ignored



Properties that do not hold a value are ignored in JSON conversion when they are set using the out of the box @(Pega-RULES:Page).pxConvertPageToString(tools, myStepPage, "json") function to convert the clipboard page to JSON string. 

Error Messages

Not Applicable

Steps to Reproduce

In an Activity perform the following steps:

1. Create a Temppage 
2. Perform a Property-set on TempPage for single value properties of different types (Text,Integer,Decimal,TrueFalse,DateTime) with some property set to value "" 
    For example:
    Property Username as string and value "john" 
    Property Account_No as integer and value "" 
    Property IsActive as TrueFalse and value True
3. Create a, Out Parameter (for example: JSONString)
4. Set Param.JSONString as @(Pega-RULES:Page).pxConvertPageToString(tools, myStepPage, "json") 
5. Perform a show property for Param.JSONString 

​The generated JSON will be similar to { "IsActive":"true" ,"Name":"john" ,"pxObjClass":"ORG-APP-Work-APPCASE" } 
Property Account_No is not present.

Root Cause

This is a product enhancement. 


HFix-25855 along with a local-change is required to achieve the required functionality. Perform the below procedure so that the generated JSON will also include null value pair properties:

1.    Download the DL which contains the HFix-29848
2.    Use Update Manager to install the hotfix without committing it
3.    Restart Pega server
4.    Search and open the library “Page” and save it in your local ruleset with or without a new name and compile it
5.    Open the OOTB function pxConvertPageToString and click Save As in the local ruleset
6.    Edit the identifier and rename it  (for example: “myConvertPageToString”)
7.    Update the library name if it was renamed during saving it to local ruleset
8.    Click Create and open button
9.    Navigate to the java tab and insert the below local-change:

Insert the below at line 3:

aOptions.putString(com.pega.pegarules.priv.clipboard.PegaClipboardPage.JsonFormatOptions.Encode.toString(), "false"); 

Insert the below at line 4:

aOptions.putString(com.pega.pegarules.priv.clipboard.PegaClipboardPage.JsonFormatOptions.ALLOW_EMPTY_PROPERTIES.toString(), "true"); 

10.    Click the Save button then Compile, generate function and library

Use the new function as follows in the activity:

@(Pega-RULES:Page).pxConvertPageToString(tools, myStepPage, "json")  /* OOTB function and should be replaced with */

@(MyRuleset:MyPage).myConvertPageToString(tools, myStepPage, "json") /* Using custom new function */

Here the custom function is “myConvertPageToString”, which is present in the custom library “MyPage” and the custom ruleset is “MyRuleset”


Published October 7, 2016 - Updated October 20, 2016

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.