lundi 21 mai 2018

Filemaker Json parsing *UPDATE*

I'm attempting to parse json information but the issue that I'm facing is that I can't get my field name to match with the field number from json and set the field to the correct value. F

Here is my code:

Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::employeesAddress ]
Set Field [ grievances::rawEmployeeAddress; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesEmail
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::email ]
Set Field [ grievances::employeesEmail; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesJobTitle
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::delegates ]
Set Field [ grievances::employeesJobTitle; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesShift
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::shift ]
Set Field [ grievances::employeesShift; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesSeniorityDate
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::seniorityDate ]
Set Field [ grievances::employeesSeniorityDate; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match Employee Department
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::department ]
Set Field [ grievances::employeesDepartment; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesSignature
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::employeeSignature ]
Set Field [ grievances::employeesSignature; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match nature of grievance
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::natureOfGrievance ]
Set Field [ grievances::grievanceNature; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match violation of Article
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::violationOfArticle ]
Set Field [ grievances::grievanceArticle; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match grievanceSection
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::section ]
Set Field [ grievances::grievanceSection; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match grievance Statement of Case
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::statementOfCase ]
Set Field [ grievances::grievanceCaseStatement; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match grievance Adjustment Requested
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::adjustmentRequested ]
Set Field [ grievances::grievanceAdjustmentRequested; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match Union Rep or Delegate Signature
Else If [ JSONGetElement ( $json ; "data[" & $i & "]field" ) = jsonFieldIDs::unionDelegateUnionRepSignature ]
Set Field [ grievances::grievanceUnionRepSignature; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
End If
Commit Records/Requests [ No dialog ]
Set Variable [ $i; Value:$i + 1 ]
Exit Loop If [ $i ≥ $dataCount ]
End Loop
// Set Field [ grievances::delegate; JSONGetElement ( $json ; "data[1].value" ) ]
// Set Field [ grievances::dateGrievanceOriginated; JSONGetElement ( $json ; "data[2].value" ) ]
// Set Field [ grievances::grievanceStep; JSONGetElement ( $json ; "data[3].value" ) ]
// Set Field [ grievances::relatedGrievance; JSONGetElement ( $json ; "data[4].value" ) ]
// Set Field [ grievances::rawNameTextFile; JSONGetElement ( $json ; "data[5].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
Commit Records/Requests [ No dialog ]
Go to Layout [ original layout ]

Here is the structure of the json Get request:

{
  "id": "383694318",
  "timestamp": "2018-02-09 15:23:45",
  "user_agent": "Mozilla/5.0 (Windows NT 6.1; rv:58.0) Gecko/20100101 Firefox/58.0",
  "payment_status": "",
  "data": [
    {
      "field": "59493345",
      "value": "first = jane\nmiddle = a\nlast = doe"
    },
],
}

I set up a table that has global variables with the filemaker field ID names set to the correct json field IDs and I was using the table to assign the right json field values to the correct field name within filemaker. For some reason my if statement fails at comparing the data.

Here is a copy of that table.

institution Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









delegates   Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









dateGrievanceOriginated Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Global
    Repetitions: 1
    Index Language: English









grievanceSubmissionID   Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Global
    Repetitions: 1
    Index Language: English









employeesName   Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









employeesAddress    Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









employeePhone   Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









email   Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









jobtitle    Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









shift   Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









seniorityDate   Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









department  Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









employeeSignature   Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









natureOfGrievance   Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









violationOfArticle  Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









section Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









statementOfCase Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









adjustmentRequested Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









unionDelegateUnionRepSignature  Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English









grievanceStep   Normal, Number  Auto-Enter:

    Allow editing

Validation:

    Only during data entry

Storage:

    Repetitions: 1
    Indexing: None
    Automatically create indexes as needed
    Index Language: English

So my new issue is that my if statement doesn't set the next field called it just updates the current field in this case institutions. My script calls the institution correctly but by the time the script concludes i'm left with the last value listed in json. So for example I have a field called firstName my script calls in jane but continues through the script and gets the doe for lastName but stores that information in the firstName field.

new code:

Set Variable [ $dataCount; Value:ValueCount ( JSONListKeys ( $json ; "data" ) ) ]
Set Variable [ $i; Value:0 ]
#needs if statement to revert changes if existing
Go to Layout [ “grievances” (grievances) ]
New Record/Request
Set Field [ grievances::_IDgrievance; JSONGetElement ( $json ; "id" ) ]
Set Field [ grievances::grievanceTimestampSubmitted; JSONGetElement ( $json ; "timestamp" ) ]
Loop
#match institution
If [ JSONGetElement ( $json ; GetAsNumber ( "data[" & $i & "].field" )) = GetAsNumber (jsonFieldIDs::institution) ]
Set Field [ grievances::institution; JSONGetElement ( $json ; "data[" & $i & "].value" ) ]
#match delegate
Else If [ JSONGetElement ( $json ; GetAsNumber ("data[" & $i & "].field" )) = GetAsNumber (jsonFieldIDs::delegates) ]
Set Field [ grievances::delegate; JSONGetElement ( $json ; "data[" & $i & "].value" ) ]
#match grievancedateorignated
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::dateGrievanceOriginated ]
Set Field [ grievances::dateGrievanceOriginated; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match grievanceStep
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::grievanceStep ]
Set Field [ grievances::grievanceStep; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match relatedgrievanceID
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::grievanceSubmissionID ]
Set Field [ grievances::relatedGrievance; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesName
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::employeesName ]
Set Field [ grievances::rawEmployeeName; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesPhoneNumber
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::employeePhone ]
Set Field [ grievances::rawEmployeePhoneNumber; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesAddress
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::employeesAddress ]
Set Field [ grievances::rawEmployeeAddress; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesEmail
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::email ]
Set Field [ grievances::employeesEmail; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesJobTitle
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::delegates ]
Set Field [ grievances::employeesJobTitle; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesShift
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::shift ]
Set Field [ grievances::employeesShift; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesSeniorityDate
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::seniorityDate ]
Set Field [ grievances::employeesSeniorityDate; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match Employee Department
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::department ]
Set Field [ grievances::employeesDepartment; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match EmployeesSignature
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::employeeSignature ]
Set Field [ grievances::employeesSignature; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match nature of grievance
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::natureOfGrievance ]
Set Field [ grievances::grievanceNature; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match violation of Article
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::violationOfArticle ]
Set Field [ grievances::grievanceArticle; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match grievanceSection
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::section ]
Set Field [ grievances::grievanceSection; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match grievance Statement of Case
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::statementOfCase ]
Set Field [ grievances::grievanceCaseStatement; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match grievance Adjustment Requested
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::adjustmentRequested ]
Set Field [ grievances::grievanceAdjustmentRequested; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
#match Union Rep or Delegate Signature
Else If [ JSONGetElement ( $json ; "data[" & $i & "].field" ) = jsonFieldIDs::unionDelegateUnionRepSignature ]
Set Field [ grievances::grievanceUnionRepSignature; JSONGetElement ( $json ; "data[" & $i & "]value" ) ]
End If
Set Variable [ $i; Value:$i + 1 ]
Commit Records/Requests [ No dialog ]
Exit Loop If [ $i ≥ $dataCount ]
End Loop
// Set Field [ grievances::dateGrievanceOriginated; JSONGetElement ( $json ; "data[2].value" ) ]
// Set Field [ grievances::grievanceStep; JSONGetElement ( $json ; "data[3].value" ) ]
// Set Field [ grievances::relatedGrievance; JSONGetElement ( $json ; "data[4].value" ) ]
// Set Field [ grievances::rawNameTextFile; JSONGetElement ( $json ; "data[5].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
// Set Field [ grievances::institution; JSONGetElement ( $json ; "data[0].value" ) ]
Commit Records/Requests [ No dialog ]
Go to Layout [ original layout ]

Aucun commentaire:

Enregistrer un commentaire