HelperFunctions
  • 29 Mar 2023
  • 3 Minutes to read
  • Dark
    Light

HelperFunctions

  • Dark
    Light

Article Summary

The HelperFunctions Adapter contains common functions used in RapidIdentity Cloud Implementations

AddAttributeChangeToObject

CalculateDateDiff

CalculateGradYear

ConvertRecordToPascalCase

ConvertStringToPascalCase

HasRecordChanged

AddAttributeChangeToObject

The AddAttributeChangeToObject is meant to add in attributes to the HasRecordChanged
return object. The HasRecordChanged return object is useful for logging and log audit events
within RapidIdentity Connect. An example for a HasRecordChanged return object is below.

{
    "givenName": {
        "old_value": "Henry",
        "new_value": "Indiana"
    }
    "sn": {
        "old_value": "Ford",
        "new_value": "Jones"
    },
    "idautoPersonJobTitles": {
        "old_value": ["IT Administrator", "HR Administrator"],
        "new_value": ["Teacher", "Coach"]
    }
}

Input Parameters

object: object

HasRecordChanged return object to add new changed value

fieldName: string

The field name to add to the object

oldFieldValue: object

The old_value of the fieldName

newFieldValue: object

The new_value of the fieldName

Return Value

The return value type is an object

Example

record1 = createRecordFromObject({
    "givenName": "Henry",
    "sn": "Ford",
    "idautoPersonJobTitles": [
        "IT Administrator",
        "HR Administrator"
     ]
})
record2 = createRecordFromObject({
    "givenName": "Indiana",
    "sn": "Jones",
    "idautoPersonJobTitles": [
        "Teacher",
        "Coach"
     ]
})
hasChanged = HasRecordChanged(record2, record1, true)
hasChanged = AddAttributeChangeToObject(hasChanged, "idautoPersonPriLocCode", 123, 456)

CalculateDateDiff

The CalculateDateDiff action takes 2 dates and returns the difference between those dates
in days

Input Parameters

initialDate: string

The first date to compare in the format of yyyyMMdd

compareDate: string

The second date to compare in the format of yyyyMMdd

invertDateDiffResult: boolean

Negates number of days. If the difference between the 2 dates in 98 and invertDateDiffResult
is true then the return would be -98

Return Value

The return value type is a Number

Example

diffDays = CalculateDateDiff("20230831", "20230531", false)
log(diffDays) // 92

CalculateGradYear

The CalculateGradYear action returns the graduation year for a specific grade level based
on the current date. If the current month is greater than June the CalculateGradYear will
add 1 to the overall calculation.

Input Parameters

grade_level: string

The grade level to calculate the graduation year

graduation_grade_level: string

The grade level in which a student graduates. The default is 12

non_numeric_mapping_file_path: string

The path to a json file containing mappings from non numeric grade levels to numeric grade levels.
The default is PK to -1 and KG to 0. An example of a json mapping file is below:

{
    "IT": -4,
    "PR": -3,
    "PK": -2,
    "TK": -1,
    "KG": 0
}

Return Value

The return value type is a Number

Example

Current date during this example is 03/15/2023

gradYearFourthGrade = CalculateGradYear(4)
log(gradYearFourthGrade) // 2031
gradYearFourthGradeWithGradYearTen = CalculateGradYear("4", 10)
log(gradYearFourthGradeWithGradYearTen) // 2029
gradYearKindergarten = CalculateGradYear("KG")
log(gradYearKindergarten) // 2035

ConvertRecordToPascalCase

The ConvertRecordToPascalCase action takes a record and converts all fields with a string
value to Pascal Case.

Input Parameters

record: record

The record to convert to Pascal Case

Return Value

The return value type is a record

Example

record = CreateRecordFromObject({
    "title": "start with why",
    "author": "simon sinek",
    "year": 2009
})
record = ConvertRecordToPascalCase(record)
log(record) // { "title": Start With Why, "author": "Simon Sinek", "year": 2009 }

ConvertStringToPascalCase

The ConvertStringToPascalCase action takes a string and converts it to Pascal Case.

Input Parameters

input: string

The string to convert to Pascal Case

unique_mapping_file_path

The path to a json mapping file for unique Pascal Case mappings. An example of this file is below:

{
    "MCBRIDE": "McBride",
    "START WITH WHY": "Start with Why"
}

Return Value

The return value type is a string

Example

str = "in west philadelphia born and raised on the playground is where i spent most of my days"
out = ConvertStringToPascalCase(str)
log(out) // In West Philadelphia Born And Raised On The Playground Is Where I Spent Most Of My Days

HasRecordChanged

The HasRecordChanged action compares two records and returns an object containing the changes.
An example of a HasRecordChanged object is below:

{
    "givenName": {
        "old_value": "Henry",
        "new_value": "Indiana"
    }
    "sn": {
        "old_value": "Ford",
        "new_value": "Jones"
    },
    "idautoPersonJobTitles": {
        "old_value": ["IT Administrator", "HR Administrator"],
        "new_value": ["Teacher", "Coach"]
    }
}

Input Parameters

new_record: record

The new record to be used in the comparison

old_record

The old record to be used in the comparison

sortArrays: boolean

Determines whether to sort return HasRecordChanged object

Return Value

The return value type is an object

Example

record1 = createRecordFromObject({
    "givenName": "Henry",
    "sn": "Ford",
    "idautoPersonJobTitles": [
        "IT Administrator",
        "HR Administrator"
     ]
})
record2 = createRecordFromObject({
    "givenName": "Indiana",
    "sn": "Jones",
    "idautoPersonJobTitles": [
        "Teacher",
        "Coach"
     ]
})
hasChanged = HasRecordChanged(record2, record1, true)

Was this article helpful?

What's Next