Objectives methods

The UI Apps SDK enables you to perform CRUD operations with Objectives from your UI App. For example, you can create Objectives based on the user's interaction with your UI App.

NOTE: Before you start using the SDK methods, ensure you have imported and configured the SDK first.

NOTE: In the Quantive Results REST API and UI Apps SDK, Objectives are referred to as goals, thus all methods below use goal in their name.

createGoal

To create an Objective, use the createGoal method and pass the properties of the Objective you are creating inside a pyaload object. For a full reference of the supported and required properties for an Objective, refer to the Create Objective REST API Endpoint documentation.

const goalPayload = {
  ownerId: "owner-id",
  ownerIds: ["owner-id"],
  description: "",
  name: "goal-name",
  attainmentTypeString: "average_kr",
  dateFrom: "2021-01-01T22:00:00Z",
  dateTo: "2021-12-31T21:59:59.999Z",
  customFields: {},
  sessionId: "session-id",
  assignee: {
    accountId: "account-id",
    avatar: "",
    color: "",
    email: "user@mail.com",
    id: "owner-id",
    name: "user name",
    picture:
      "https://user-picture",
    type: "user",
  },
  assignees: [
    {
      accountId: "account-id",
      avatar: "",
      color: "",
      email: "user@mail.com",
      id: "owner-id",
      name: "user name",
      picture:
        "https://user-picture",
      type: "user",
    },
  ],
  };

sdk
  .createGoal(goalPayload)
  .then((goal) => console.log(goal));

getGoals

To get a list of Objectives use the getGoals method. You can pass additional filtering, paging, sorting and field projection parameters in a payload object. For, to get the first 50 Objectives from a given session and include selected properties of the Objectives and their Key Results you can say:

const goalParams = {
  filter: {
    sessionId: {
      $in: ["some-session-id"],
    },
  },
  sort: "-attainment",
  skip: 0,
  limit: 50,
  fields:
    "metrics{id,confidence,name,attainment,ownerIds,manualType,lastCheckInDate,cascadeType,links},
    parentId,ownerIds,description,name,dateFrom,dateTo,childrenCount,fullSubTreeCount,metricsCount,
    attainment,fullAggregatedAttainment,sessionId,customFields,obfuscated,private,workflow{status},
    locked,tags{name,title,itemsTaggedCount},attainmentTypeString",
};

sdk
  .getGoals(goalParams)
  .then((goals) => console.log(goals));

Check out the Get Objectives REST API endpoint for a full list of the supported parameters you can pass in your query. For more information on constructing the filter expression, paging, sorting and field projection refer to these articles:

getGoal

To get an existing Objective, use the getGoal method and pass the desired objective Id. For example:

const goalId = "some-test-goal-id";

sdk
  .getGoal(goalId)
  .then((goal) => console.log(goal));

updateGoal

To update an Objective, use the updateGoal method. Pass the desired properties you must update in a payload object. For example, to update the name of an objective you can say:

const updateGoalPayload = { id: "some-test-goal-id", name: "my-new-goal-name"};

sdk
  .updateGoal(updateGoalPayload)
  .then((goal) => console.log(goal));

NOTE When updating an Objective, you must always pass an id property in your payload with the value of the desired Objective's Id.

deleteGoal

To delete an Objective, use the deleteGoal method and pass the desired Objective Id. For example:

const goalId = "some-test-goal-id";

sdk.deleteGoal(goalId);

onGoalUpdated

To receive goal update event.

sdk.onGoalUpdated((event) => {
  console.log(event);
});