최근 검색


최근 검색 없음

Zendesk App Button

답변함


2021년 10월 14일에 게시됨

Hi,

In modal.html, create a button. In the first function getData(), I can retrieve the sunshine object ID dynamically. Is there a way to also retrieve the ticket.requester.id and the sunshine.object.id in the buttonOrder() function? I bold these two variables in the function.

Any guidance is appreciate, thanks!

 

<body>
<button class="c-btn c-btn--primary" onClick="buttonOrder()">Buy Product</button>
</body>
var client = ZAFClient.init();
client.on('app.registered', init);

function init(){
var hashes = window.location.hash;
var param = hashes.split('&');
id = param[0].replace('#','');
requester_id = param[1];
getData();
};

//Function - Get data from custom objects
function getData(){
//Get object's attributes
var objectSettings = {"url": "/api/sunshine/objects/records/" + id};
client.request(objectSettings).then(function(response){

//Loop through object's attributes and create list (see function below)
createAttributeList(response);

//Get events related to current object, loop through and create list (see function below)
createEventList(response);
}).catch(function(error){

//Display error message (see function below)
showCoError(error);
});

function buttonOrder() {

let options = {

url: 'https://d3v-test.zendesk.com/api/v2/users/'+ ticket.requester.id + '.json',
type: 'PUT',
dataType: 'json',
contentType: 'application/json',
cors: true,
data: JSON.stringify({
"user": {"order_id": sunshine.object.id}
})
};

2

1

댓글 1개

image avatar

Eric Nelson

Zendesk Developer Advocacy

Hey Jose,

You could use the client.get method to get the requester id. Another option would be to just pass the response from getData to some global variables, which then could be ingested via buttonOrder.

Hope this helps,

Eric

2


댓글을 남기려면 로그인하세요.

원하는 정보를 못 찾으셨나요?

새 게시물