Question
· Jul 18, 2023

Method to return value of object element

I am trying to write a class method to return the value of a object element.  Input to method is the object and element. I am not getting a value returned. What am I missing?

ClassMethod GetObjectFieldValue(pObject As %DynamicAbstractObject, pField As %String) As %String
{
    quit:pObject="" ""
    quit:pField="" "" set tResponse=""
    set tResponse = pObject.%Get(pField)
    return tResponse

}

Here is my input data,

{
    "priority": "2",
    "lastmodifieduser": "PORTAL",
    "assignedto": "jdoe01 STAFF",
    "status": "REVIEW",
    "documentclass": "PATIENTCASE",
    "versiontoken": "937486",
    "departmentid": "999",
    "patientcaseid": "105555424",
    "providerusername": "jdoe01",
    "internalnote": "firstMessage",
    "subject": "first123",
    "patientid": 9877654321,
    "createduser": "PORTAL",
    "description": "patient case - first123",
    "documentroute": "MDP",
    "documentsubclass": "PATIENTCASE_CLINICALQUESTION",
    "documentsource": "PORTAL",
    "createddate": "07/17/2023",
    "lastmodifieddate": "07/17/2023"
}

Product version: IRIS 2021.2
Discussion (8)2
Log in or sign up to continue

Did a little test:

Class dc.test Abstract ]
{

ClassMethod GetObjectFieldValue(
  pObject As %DynamicAbstractObject,
  pField As %StringAs %String
{
  quit:pObject="" ""
  quit:pField="" "" set tResponse=""
  set tResponse pObject.%Get(pField)
  return tResponse
}

ClassMethod Test()
{
  p1={
    "priority""2",
    "lastmodifieduser""PORTAL",
    "assignedto""jdoe01 STAFF",
    "status""REVIEW",
    "documentclass""PATIENTCASE",
    "versiontoken""937486",
    "departmentid""999",
    "patientcaseid""105555424",
    "providerusername""jdoe01",
    "internalnote""firstMessage",
    "subject""first123",
    "patientid"9877654321,
    "createduser""PORTAL",
    "description""patient case - first123",
    "documentroute""MDP",
    "documentsubclass""PATIENTCASE_CLINICALQUESTION",
    "documentsource""PORTAL",
    "createddate""07/17/2023",
    "lastmodifieddate""07/17/2023"}
    
  p2="documentsubclass"
  ..GetObjectFieldValue(p1,p2)
}

}

Result:

USER>##class(dc.test).Test()
PATIENTCASE_CLINICALQUESTION

It works also for me... maybe it depends on how Michael Wood is passing the json object to the method... 

If he is passing a string, there is a conversion needed from string to %DynamicAbstractObject like:

Set str="{""prio"":""2"",""code"":""A001""}"
Write str
{"prio":"2","code":"A001"}
Set obj=##Class(%DynamicAbstractObject).%FromJSON(str)
Write obj
1@%Library.DynamicObject
ZW obj
obj={"prio":"2","code":"A001"}  ; <DYNAMIC OBJECT>