Create Kb Article from client script using create record in UI builder service now

sapnasarkar
Tera Contributor

for the below given code i am not getting any error or response i don't know what's the error in the script i am trying to create knowledge article from this script. The script is triggered but nothing is working

 

 

/**
* @Param {params} params
* @Param {api} params.api
* @Param {any} params.event
* @Param {any} params.imports
* @@param {ApiHelpers} params.helper
*/
function handler({api, event, helpers, imports}) {
  console.log("test");
  // Define static knowledge article content
  const shortDescription = "Quick Tips: Creating Knowledge in ServiceNow";
  const articleBody = `
    <html>
      <body>
        <h2>Using UI Builder to Create Articles</h2>
        <p>This article was programmatically created using client scripting in Now Experience.</p>
        <p>You can add <b>HTML</b> content, lists, images, and more.</p>
        <ul>
          <li>Use <i>templateFields</i> to pass data</li>
          <li>Execute createRecord resource</li>
        </ul>
      </body>
    </html>
  `;

  const knowledgeBaseSysId = "dfcb"; // Or use actual sys_id from kb_knowledge_base table



 const payloadFields = {
        short_description: shortDescription,
        text: articleBody,
        kb_knowledge_base: knowledgeBaseSysId
    };

 
  api.data.create_record_1.execute({
        table: "kb_knowledge",
        templateFields: payloadFields
     
    })
    .then(response => {
      console.log("Article creation success:", response);
    })
    .catch(error => {
      console.error("Article creation failed:", error);
    });
}

 #kbarticle #clientscript #uibuilder 

0 REPLIES 0