[Note] 아래 코드는 커스텀 솔루션에 대한 가이드라인 및 샘플입니다. 코드의 동작 여부 및 에러발생에 대한 유지보수는 젠데스크가 책임 지지 않습니다. 추가 문의가 있을 경우 영업담당자 또는 Zendesk 고객 지원팀에 문의하기 로 연락 부탁드립니다.
1.텍스트 티켓 필드 생성
2. 아래 스크립트를
new_request_page.hbs에 추가 (생성한 티켓필드 ID 교체)
<!-- Pass the title of the most recently viewed
article to a hidden custom ticket field
-->
<div style="display: none">
{{recent_articles}}
</div>
<script>
document.addEventListener('DOMContentLoaded', async function() {
const ticketFieldId = 4463419211801;
const recentlyViewedArticles = document.querySelector('.recent-articles ul');
const mostRecentlyViewedArticle = recentlyViewedArticles.firstChild;
let mostRecentlyViewedArticleId = mostRecentlyViewedArticle.firstChild.getAttribute('href');
mostRecentlyViewedArticleId = mostRecentlyViewedArticleId.split('/articles/')[1];
const getCurrentLocale = () => {
const pathname = window.location.pathname;
const currentLocale = pathname.substring(
pathname.indexOf("/hc/") + 4,
pathname.lastIndexOf("/requests/new")
);
return currentLocale;
};
const getArticle = (locale, id) => {
return fetch(`/api/v2/help_center/${locale}/articles/${id}`).then(article => article.json());
};
// fetch article using locale found in current URL
let articleInCurrentLocale = await getArticle(getCurrentLocale(), mostRecentlyViewedArticleId);
articleInCurrentLocale = articleInCurrentLocale.article;
const { source_locale } = articleInCurrentLocale;
// fetch article again using its source locale
let articleInSourceLocale = await getArticle(source_locale, mostRecentlyViewedArticleId);
articleInSourceLocale = articleInSourceLocale.article;
// pass article title to custom ticket field value
document.querySelector(`#request_custom_fields_${ticketFieldId}`).value = articleInSourceLocale.title;
// hide custom ticket field
document.querySelector(`.request_custom_fields_${ticketFieldId}`).hidden = true;
});
</script>
댓글
댓글 0개
댓글을 남기려면 로그인하세요.