Change the table field value with the ui action client script

FarhathH
Tera Contributor

I am implementing a publish action for a knowledge article in the knowledge table. When I click the ui action button it will run the following function.

 

 

function publish_kb() {
    var gm = new GlideModal("knowledge_review_confirmation", true, 600);
    gm.setBackdropStatic(true);
    gm.setTitle("Feedback");
    gm.setPreference("title", "Your article is submitted for the approval");
    gm.setPreference("onPromptComplete", function() {
        g_form.setValue('u_state', 'modified');
        gsftSubmit(null, g_form.getFormElement(), 'publish_knowledge');
    });
    gm.setPreference("onPromptCancel", function() {
        if (g_form.getValue('u_generated_by') == 'ai') {
            g_form.setValue('u_state', 'not_modified');
        }
        gsftSubmit(null, g_form.getFormElement(), 'publish_knowledge');
    });
    gm.render();
}

if (typeof window == 'undefined')
    serverReopen();

function serverReopen() {
    if (new KBKnowledge().canPublish(current)) {
		gs.info('function not going');
        var prevValue = current.workflow_state + '';
        if (current.kb_knowledge_base.kb_version == "3" && new KBWorkflow().startWorkflow(current, "workflow")) {
            //If publish sub workflow is completed, workflow engine would have already done current.update()
            if (current.workflow_state != 'published')
                current.update();
            var knowledge = new GlideRecord("kb_knowledge");
            if (knowledge.get(current.sys_id) && prevValue != knowledge.getValue("workflow_state")) {
                gs.addInfoMessage(new KBKnowledge().getStateMessage(knowledge.getValue("workflow_state")));
            }
        } else if (current.kb_knowledge_base.kb_version == "2") {
            current.workflow_state = 'published';
            current.update();
            gs.addInfoMessage(new KBKnowledge().getStateMessage(current.getValue("workflow_state")));
        }
    }
}

 

 

 this will generate a  glide model I created 

 

 

<style>
  .dialog_content {
      width: auto;
      height: auto;
      vertical-align: middle;
      min-width: 500px;
      padding: 0 10px 10px 10px;
  }
  .dialog_buttons {
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 10px;
      gap: 10px;
      width: auto;
  }
  .dialog_button {
      width: 7em;
  }
</style>

<g:ui_form onsubmit="return invokePromptCallBack();">
  <g:evaluate>
      var title = "${RP.getWindowProperties().get('title')}";
      title = new GlideStringUtil().unEscapeHTML(title);
  </g:evaluate>
  <table border="0" width="100%">
      <tr>
          <td>
              <table border="0" width="100%">
                  <tr>
                      <td class="dialog_content">$[title]</td>
                  </tr>
                  <tr>
                      <td class="dialog_content">
                          <p><strong>Modified: </strong> I have modified the content.<br></br><strong>Not Modified: </strong> No modification needed for the article.</p>
                          <p><em>Note: Your response is used solely for statistical purposes to help us improve the quality and accuracy of our article generation process.</em></p>
                          <p>Please confirm whether you have modified the content of the generated article</p>
                      </td>
                  </tr>
                  <tr>
                      <td class="dialog_buttons_container">
                          <div class="dialog_buttons">
                              <g:dialog_button
                                  id="${jvar_ok_id}"
                                  type="button"
                                  onclick="invokePromptCallBack('ok');"
                                  class="dialog_button">
                                  ${gs.getMessage('Modified')}
                              </g:dialog_button>
                              <g:dialog_button
                                  id="${jvar_cancel_id}"
                                  type="button"
                                  onclick="invokePromptCallBack('cancel')"
                                  class="dialog_button">
                                  ${gs.getMessage('Not Modified')}
                              </g:dialog_button>
                          </div>
                      </td>
                  </tr>
              </table>
          </td>
      </tr>
  </table>
</g:ui_form>

 

 

 and the client side script is 

 

 

function invokePromptCallBack(type) {
    var gdw = GlideDialogWindow.get();
    if (type == 'ok')
        var f = gdw.getPreference('onPromptComplete');
    else
        var f = gdw.getPreference('onPromptCancel');
    if (typeof(f) == 'function') {
        try {
            f.call(gdw, gdw.getPreference('oldValue'));
        } catch (e) {}
    }
    gdw.destroy();
    return false;
}

 

 

 
the problem I am facing is when i click the button it is showing the glide dialog model and when i click the button server side is working but the state that i am updating through g_form is not working. Let me know if you know the problem and solution for this .

Thanks in advance

0 REPLIES 0