Scripted Rest message Get menthod not getting HTML field type value

Rushi2
Tera Expert

Hi All, 

 

I am developing a scripted Rest message Get method, to get the KBs.  Here I am not able to get HTML-type fields. 

 

Can someone help me to get HTML in the get method?

 

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
    var val = [];
    // implement resource here//
    var grchatgpt = new GlideRecord('kb_knowledge');
    grchatgpt.addEncodedQuery("workflow_state=published^kb_knowledge_base=100c36a80f115244272e244be1050e88");
    grchatgpt.orderByDesc('sys_updated_on');
    grchatgpt.query();
    while (grchatgpt.next()) {
        var abc = grchatgpt.kb_introduction.toString();
        var res = {
            "Number": grchatgpt.getValue('number'),
            "knowledge base": grchatgpt.getDisplayValue('kb_knowledge_base'),
            "valid to": grchatgpt.getValue('valid_to'),
            "short description": grchatgpt.getValue('short_description'),
            "Assignment group": grchatgpt.getDisplayValue('u_assignment_group'),
            "Internal notes": grchatgpt.getValue('u_internal_notes'),
            "kb instructions": grchatgpt.getDisplayValue('kb_instructions'),           ----  HTML 
            "kb support details": grchatgpt.getDisplayValue('u_kb_support_details'),  - HTML
          "kb  details": grchatgpt.getDisplayValue('kb_introduction'),     - HTML
           

        };
        val.push(res);
    }
    response.setBody(val);

})(request, response);
 
Regards, 
Rushi
1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Rushi2 Please use the updated code and see if it works for you.

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
    var val = [];
    // implement resource here//
    var grchatgpt = new GlideRecord('kb_knowledge');
    grchatgpt.addEncodedQuery("workflow_state=published^kb_knowledge_base=100c36a80f115244272e244be1050e88");
    grchatgpt.orderByDesc('sys_updated_on');
    grchatgpt.query();
    while (grchatgpt.next()) {
        var abc = grchatgpt.kb_introduction.toString();
        var res = {
            "Number": grchatgpt.getValue('number'),
            "knowledge base": grchatgpt.getDisplayValue('kb_knowledge_base'),
            "valid to": grchatgpt.getValue('valid_to'),
            "short description": grchatgpt.getValue('short_description'),
            "Assignment group": grchatgpt.getDisplayValue('u_assignment_group'),
            "Internal notes": grchatgpt.getValue('u_internal_notes'),
            "kb instructions": grchatgpt.getValue('kb_instructions'),          
            "kb support details": grchatgpt.getValue('u_kb_support_details'),  
          "kb  details": grchatgpt.getValue('kb_introduction')
        };
        val.push(res);
    }
    response.setBody(val);

})(request, response);

View solution in original post

6 REPLIES 6

AnveshKumar M
Tera Sage
Tera Sage

Hi @Rushi2 

getDisplayValue or getValue both gets you the HTML type field contents. But while passing it over the REST , it's better to escape the HTML.

 

Are you getting all the field values when you hit the actual API except the HTML fields? Or the API itself is not working?

Thanks,
Anvesh

Sandeep Rajput
Tera Patron
Tera Patron

@Rushi2 Please use the updated code and see if it works for you.

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
    var val = [];
    // implement resource here//
    var grchatgpt = new GlideRecord('kb_knowledge');
    grchatgpt.addEncodedQuery("workflow_state=published^kb_knowledge_base=100c36a80f115244272e244be1050e88");
    grchatgpt.orderByDesc('sys_updated_on');
    grchatgpt.query();
    while (grchatgpt.next()) {
        var abc = grchatgpt.kb_introduction.toString();
        var res = {
            "Number": grchatgpt.getValue('number'),
            "knowledge base": grchatgpt.getDisplayValue('kb_knowledge_base'),
            "valid to": grchatgpt.getValue('valid_to'),
            "short description": grchatgpt.getValue('short_description'),
            "Assignment group": grchatgpt.getDisplayValue('u_assignment_group'),
            "Internal notes": grchatgpt.getValue('u_internal_notes'),
            "kb instructions": grchatgpt.getValue('kb_instructions'),          
            "kb support details": grchatgpt.getValue('u_kb_support_details'),  
          "kb  details": grchatgpt.getValue('kb_introduction')
        };
        val.push(res);
    }
    response.setBody(val);

})(request, response);

Hi Sandeep 

 

Thank you so much for your response, Still, I am not getting HTML fields.

 

     "kb instructions": null,
      "kb support details": null,
      "kb  details": null

@Rushi2 Can you confirm if the values for fields 

kb_instructions, u_kb_support_details, kb_introduction

exist on the kb article? Can you log the sys_id of the kb articles and search them on the instance to check if these fields are actually having data on them?