Key Results methods
The UI Apps SDK enables you to perform CRUD operations with Key Results. For example, you can enable users to update the Key Result your UI app is currently loaded for.
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, Key Results are referred to as metrics, thus all methods below use metric in their name.
createMetric
To create a Key Result from your UI App, use the createMetric SDK method. You must pass a payload object where you set the desired properties of the new Key Result you are creating. Refer to the Create Key Result REST API endpoint for additional information about the available and required properties you must set.
const createMetricPayload = {
id: metricId,
ownerId: "owner-id",
ownerIds: ["owner-id"],
goalId: "goal-id",
manualType: "double",
targetOperator: "at_least",
initialValue: 1,
target: 12,
critical: null,
name: "test",
dueDate: "0001-01-01T00:00:00Z",
softDueDate: "0001-01-01T00:00:00Z",
links: {},
customFields: {},
format: { prefix: "", suffix: "", fractionSize: 0 },
insightName: "",
actual: 1,
};
sdk
.createMetric(createMetricPayload)
.then((metric) => console.log(metric));
getMetric
To get a Key Result use the getMetric method and pass the KR Id. For example:
const metricId = "metric-id";
sdk
.getMetric(metricId)
.then((metric) => console.log(metric));
getGoal.metrics
To get the Key Results under a specified Objective, use the getGoal method first, passing the desired Objective Id. The KRs under that objective are available in the metrics object of the response, so you can say something like:
const goalId = "goal-id";
sdk
.getGoal(goalId)
.then((goal) => console.log(goal.metrics));
updateMetric
To update an existing Key Result, use the updateMetric method and pass a payload object containing the properties you must update.
const updateMetricPayload = { id: "some-test-metric-id", name: "my-new-metric-name"};
sdk
.updateMetric(updateMetricPayload)
.then((metric) => console.log(metric));
NOTE When you are updating a Key Result You must always pass an id property in your payload and set its value to the Id of the Key Result you are updating.
deleteMetric
To delete a Key Result, use the deleteMetric method and pass the desired key Result Id. For example:
const metricId = "some-test-metric-id";
sdk.deleteMetric(metricId);
checkinMetric
To post a Key Result update (programatically referred to as checkin) use the checkinMetric UI Apps SDK method. You must pass the Id of the KR you wish to update, as well as construct a payload with the following required properties:
- checkInDate - the date of this KR update
- actual - the updated Key Result value
- comment - add any text you want to add as KR update note.
For example:
const metricId = "some-metric-id";
const checkin = {
checkInDate: new Date().toISOString(),
actual: 10,
comment: "A comment for this specific checkin",
};
sdk.checkinMetric({ id: metricId, checkin }).then((newCheckin) => console.log(newCheckin));
createMetricReaction
To post a Key Result update with an emoji, where emoji and name properties should be a valid emoji codes. The targetId is the id of the metric update message. The targetType is always "checkin".
sdk.createMetricReaction({
createReaction: {
"emoji": "😙",
"name": "kissing-face-with-smiling-eyes",
"targetId": "targetId",
"targetType": "checkin"
},
isReactionOnGif: false
}).then(response => console.log(response));
deleteMetricReaction
The reactionName should be a valid emoji name. The targetId is the id of the metric update message.
sdk.deleteMetricReaction({
"reactionName": "kissing-face-with-smiling-eyes",
"targetId": "targetId",
}).then(response => console.log(response));
deleteMetricSnapshot
To delete a metric update snapshot.
sdk.deleteMetricSnapshot({
metricId: "metricId",
snapshotId: "snapshotId"
}).then(response => console.log(response));
patchMetricComment
To update metric snapshot message and image. Every property is mandatory.
sdk.patchMetricComment({
metricHistoryId: "metricHistoryId",
comment: {
comment: "Metric snapshot message",
gif: {
id: "id",
url: "https://media.tenor.com/images/id/tenor.gif"
}
}
}).then(response => console.log(response));
onMetricUpdated
To receive metric update event.
sdk.onMetricUpdated((event) => {
console.log(event);
});