Skip to Main Content

Intelligent Advisor

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Please ask technical questions in the appropriate category. Thank you!

Here's my working example of how to create an entity instance programmatically

20goto10Nov 2 2019

Hi all,

I wanted to share my solution for creating entity instances on the fly in javascript.  It's taken me days of scratching my head and being frustrated at the lack of information available so I'm posting this here for anyone who may have the same issue in future.

The use case is this:  we want to have an application form for students to apply for courses.  The course names and IDs are not in Service Cloud and can only be retrieved through an API endpoint.  The form needs to do the following:

  • Load all of the courses available to study (somewhere around 4000+ - much too long for a drop down list)
  • Allow the student to choose at least 1 and up to 4 subjects
  • Collect the student's personal information (name etc)

This is basically a shopping cart app where the products are not known ahead of time to OPA.  Sounds simple enough but with OPA, anything not done in rules or through configuration is never simple.  The minute customisation is involved the whole process becomes very complicated.  Here is my solution:

  • The student and their personal data are a part of the Global entity
  • The courses available become a child of the student called Course.

This relationship mimics the 1:many relationship.

Next step was to read in all the courses and create the instances of the Course, assign those instances to the Student->Course relationship and job done.  Or so I thought.  This turned out to be a lot of work and incredibly difficult to do in code until I found, squirrelled away in the documentation, a small sample of how to code the Relationship control in javascript.  This formed the basis for my working example (attached).

I am using a 3rd party library (https://datatables.net/ ) to render a nice searchable table of all the courses because I don't want to reinvent the wheel.  This library is stored in the interview-theme folder.

I hope this helps someone in future.  I tried to make the sample as simple as possible but this one is not for the feint hearted.

Cheers,

Annie

Comments
Post Details