Thanks for responding.
while i was using your code, i am getting this error in response, which says "read" method is unknown
{
"Error": "ERROR #5002: Cache error: <METHOD DOES NOT EXIST>zCheckMissingRoleName+3^Controllers.Roles.2 *Read,%Library.ListOfObjects"
}
If just take out that "read method", then i am getting this error
{
"Error": "ERROR #5002: Cache error: <INVALID OREF>zCheckMissingRoleName+16^Controllers.Roles.3"
}
I will give my requirement as it is.
I am getting an json array of Roles object, in which only "name" property is sent. I have to see if these names are present in DB or not. In case there is a new name in the json, then i have to pick that value and save it in DB.
version - 2015.1.OHS.3703.0
i have a json request as follows:
[
{
"Name":"Billing"
},
{
"Name":"Lead"
},
{
"Name":"Coordinator"
},
{
"Name":"Director"
},
{
"Name":"Main"
},
{
"Name":"Marketing"
},
{
"Name":"Workshop"
},
{
"Name":"In-House Trainer"
},
{
"Name":"Committee"
},
{
"Name":"Facilitator"
},
{
"Name":"Facilitator"
}
]
Now my code : Controller
{
#dim newObj As Model.Role
#dim %request As %CSP.Request
#Dim MyStrings As %ListOfObjects
set inputParms = %request.Content
set MyStrings = inputParms.data
Set resultu=##class(%ResultSet).%New("%DynamicQuery:SQL")
Do resultu.Prepare("select Name from Model.Role ") //
Do resultu.Execute()
set i=1
while (resultu.Next())
{
set namesArray(i) = resultu.Data("Name")
set i=i+1
//write namesArray(i)
}
for k=1:1:MyStrings.Size
{
for j=1:1:i
{
if ( MyStrings.GetAt(k).Name '= namesArray(j) ) { }
else { break }
}
// i is size of array and j is size of above loop i.e coldn't find match, and reached the end
if (i = j)
{
set newObj = ##class(Model.Role.%OpenId(MyStrings.GetAt(k).ID)
set newObj.Name=MyStrings.GetAt(k).Name
// write MyStrings.GetAt(k)
Do newObj.%Save()
}
}
return $$$OK
}
After sending the request using Postman, i am getting this error:
{
"Error": "ERROR #5002: Cache error: <PROPERTY DOES NOT EXIST>zCheckMissingRoleName+2^Controllers.Roles.2 *data,%Library.ListOfObjects"
}
and one more thing, how do i print something on the console? Just for debugging
Thanks for responding patiently. Problem is solved.
May i know how to compare two strings for equality.
like,
"inter" = "inter" ( true )
"black"="white " ( false )
"inter system"="inter sy" ( false )
"inter systems"="inter systems" ( true )
As you can see from above that it should be an exact match. Is there any method to do so with String.