Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
readAll(id==@p:demo:r:21af3bb6-49c05b37 or viewInstanceRef==@p:demo:r:21af3bb6-49c05b37) 	   // 1
  .swizzleRefs 																				                                                                              // 2
  .removeCol("mod") 																		                                                                        // 3
  .map(r => 																					                                                                                 // 4
      if (r.has("userRef")) 																                                                                 // 5
        r.merge({userRef: @otherUserId}) 
      else
        r
  )
  .each(r => diff(null, r, { add }).commit) 													                                                 // 6
  1. readAll(id==@p:demo:r:21af3bb6-49c05b37 or viewInstanceRef==@p:demo:r:21af3bb6-49c05b37): here we are capturing the viewletInstance making up our "view" that we are copying as well as all references to that viewletInstance - which makes up the viewlets belonging to the view. If we were to only execute our command on the view itself we'd lose all of our viewlets!
  2. swizzleRefs: is a SkySpark library function that takes all the IDs of all the records passed in via a grid and transforms those IDs to new IDs; this is necessary so that we have new IDs to add to our folio database (since we couldn't re-use the existing unique IDs). This function also ensures that all references that existed in the grid are maintained so that although our viewInstance is getting a new ID, all the viewInstanceRefs are updated to this new ID preserving what viewlets existed in our view.
  3. removeCol("mod"): this removes the SkySpark "mod" column that tracks modification dates for the record, these are new records being inserted so they can't have a pre-existing mod column.
  4. map(r => doStuff): map is a SkySpark Axon library function that takes in all the records in the grid and performs a transformation on them
  5. if statement: our if-statement takes any records with an existing userRef and transforms that userRef to be our new user that we are copying to (in this case "otherUserId"). Note that this user id will more likely look something like @p:project:r:user in the wild. In our case, the only record with a userRef is our viewInstance.
  6. each statement: here we are taking our final grid of results and creating a SkySpark Folio database "Diff" for each record so that we can then commit it to the database thus creating the new records for the user. 

...