I am coming to a problem where I am moving from sql query to use of an api. So, I started doing the same thing that my sql statement is doing. But for some reason it is retrieving all the job status and job class and pay grades. However, what my expected results should be is where when I delete a job_class which is something like 0707 from the json or from the database it will show on my screen that that job class is missing if no job class is missing then it will just show a Struct (empty). Can anyone tell me what I am doing wrong in my code? thanks for the help.
SQL:
select distinct job_class, PAY_GRADE
from app.my_databaseFone
where job_status like 'Active'
order by job_class
Code:
<cffunction name="my_api"
access="private"
description="my api data">
<cfset qFullmyApi = fileRead("C:\Users\Desktop\myjson.json")>
<cfset jsonData = deserializeJSON(qFullmyApi) />
<cfscript>
myAPIOutput = {};
for (item in jsonData) {
if (structKeyExists(myAPIOutput, item.jobStatus)) {
matchedValue = false;
for (i=1; i <= arrayLen(myAPIOutput[item.jobStatus]); i=i+1) {
if (item.jobClass == myAPIOutput[item.jobStatus][i].job_class
&& item.payGrade == myAPIOutput[item.jobStatus][i].pay_grade) {
matchedValue = true;
break;
}
}
if (matchedValue == false) {
arrayAppend(myAPIOutput[item.jobStatus], {"JOB_CLASS":item.jobClass,
"PAY_GRADE": item.payGrade});
}
} else {
myAPIOutput[item.jobStatus] = [{"JOB_CLASS":item.jobClass,
"PAY_GRADE": item.payGrade}];
}
}
return myAPIOutput;
</cfscript>
</cffunction>