cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
798
Views
0
Helpful
4
Replies

Dealing with null within JSON documents using UCCX 11.6

James Hawkins
Level 8
Level 8

Hi,

I have a UCCX system and have written a script that talks to a CRM API using REST.

The data is returned in JSON format. For most entries I can parse the required data ok using the Get JSON Document Data step but I am having issues with one particular field - parentCompanyID - as shown below.

 

{
    "items": [
        {
            "companyID"283,
             "companyName" "ACME Corp",
             "parentCompanyID": null
        }
    ]
}
 
The parentCompanyID field contains either an integer (if a parent company exists), or a value of null as shown above (if no parent company exists).
If I try to parse the value using the Get JSON Document Data step and store the value in an integer variable the script works ok if a parent company exists but fails if the JSON document contains "parentCompanyID": null
 
I guess it is failing because null is not an integer. Does anyone know how this can be resolved?
Thanks
James
4 Replies 4

Hi @James Hawkins 

I think that this solution might work:

  1. Create a new variable with the type "object" - this should be a generic Java object
  2. Assign this variable as you assign currently the integer
  3. Use if to determinate if variable is null or not
  4. If it's not new, then use the assignment for integer
  5. If it's null - define what should be done there.
Marek https://gaman-gt.com
UCCE, PCCE, UCCX, WxCC, Cisco Finesse, Custom Gadget, CVP, CUIC, CUCM

Hi Marek,

Thank you for the response. What you have suggested seems logical but I cannot create a variable of type "object" within the CCX editor.

Looking at some of the DevNet documentation it seems that some of the Java steps available previously in CCX have been deprecated.

 

https://developer.cisco.com/docs/contact-center-express/#deprecated-java-steps 

 

The doc linked above says that the deprecated functionality can be replaced by using the CCX Expression Language is Set steps etc. but that is a bit beyond my skill levels.

 

I have implemented a workaround where I search the string containing the text of the API response for "parentCompanyID": null using the expression below in an IF step:

 

strCompanyResponse != strCompanyResponse.contains(u"\"parentCompanyID\":null")

 

This does what I need but is pretty ugly and I would still be interested in better ways to solve this issue.

Thanks

James

 

 

@James Hawkins 

this is how you can create the object type variable (upper/lower case is important here):

 

Object.png

 

Marek https://gaman-gt.com
UCCE, PCCE, UCCX, WxCC, Cisco Finesse, Custom Gadget, CVP, CUIC, CUCM

david.macias
VIP Alumni
VIP Alumni

The way I dealt with it when using SFDC API is that I just checked for null. You can even create a function that checks for null or “”. This was not ideal, but could work in addition to what Marek suggested.

 

david