Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 150956

Re: Show approval comments on task details screen in wrapper

$
0
0

I was able to get this working by the use of some AJAX. I downloaded and pasted the jquery library "jquery-1.10.2.min.js" from jquery.com and pasted it directly into my VSM installation.

 

I created 3 new files: Default.aspx, Default.aspx.cs, and web.config

 

Contents of Default.aspx:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

 

Contents of Default.aspx.cs:

 

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
public partial class _Default : System.Web.UI.Page
{    protected void Page_Load(object sender, EventArgs e)    {        Response.Expires = -1;        Response.ContentType = "text/plain";        if (Request.QueryString["ajaxfunction"] != null)        {            try            {                Int16 intFunction = Int16.Parse(Request.QueryString["ajaxfunction"].ToString());                switch (intFunction)                {                    case 1:                        if (Request.QueryString["tasknumber"] != null)                        {                            Int64 intTaskNumber = Int64.Parse(Request.QueryString["tasknumber"].ToString());                            Response.Write(getTaskApprovalComments(intTaskNumber.ToString()));                        }                        break;                    default:                        Response.Write("ERROR: Invalid Function!");                        break;                }            }            catch (Exception exception)            {                Response.Write("ERROR: " + exception.Message);            }        }        Response.End();    }    private String getTaskApprovalComments(String strTaskNumber)    {        String strTaskApprovalComments = "";        using (OracleConnection conn = new OracleConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["vsm_connection"].ToString()))        {            conn.Open();            using (OracleCommand cmd = new OracleCommand())            {                cmd.Connection = conn;                cmd.CommandText = "SELECT NVL(TO_CHAR(h.HISTORY_DATE, 'fmMM/DD/YYYY HH:MI:SS AM') || ' - ' || p.DISPLAY || ' - ' || h.HISTORY_DESC_HTML || '<br/>', 'No Approval Comments') AS \"CUSTOM_APPROVAL_COMMENTS\" FROM CR_TASK_HISTORY h INNER JOIN AR_PERSON p ON p.REF = h.OFFICER_REF WHERE h.task_no = :TaskNumber AND h.APPROVAL_COMMENTS = 1";                cmd.CommandType = CommandType.Text;                cmd.BindByName = true;                cmd.Parameters.Add(":TaskNumber", strTaskNumber);                using (OracleDataReader dr = cmd.ExecuteReader())                {                    while (dr.Read())                    {                        strTaskApprovalComments = strTaskApprovalComments + dr.GetValue(0);                    }                }            }        }        return strTaskApprovalComments;    }
}

 

Contents of Web.config:

 

<?xml version="1.0"?><!--  For more information on how to configure your ASP.NET application, please visit  http://go.microsoft.com/fwlink/?LinkId=169433  --><configuration>  <connectionStrings>    <add name="vsm_connection" connectionString="Data Source=[Your Data Source];User Id=[Your User Name];Password=[Your Password];"/>  </connectionStrings>  <system.web>    <compilation debug="true">      <assemblies>        <add assembly="Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>      </assemblies>    </compilation>    <customErrors mode="Off"/>  </system.web></configuration>

 

 

I put these three files in a folder called AJAX inside of my system installation folder on the VSM server.

 

I then added the following code to the Custom_InTaskDetails_CustomerApproval.js folder:

 

function getApprovalComments() {
 $.ajax({  url: "AJAX/Default.aspx",  data: {  ajaxfunction: 1,  tasknumber: document.getElementById("TASK_NO").value  },  type: "GET",  dataType: "text",  success: function (data) {   document.getElementById("container_CUSTOM_APPROVAL_COMMENTS").innerHTML = data;                },  error: function (xhr, response, error, msg) {   document.getElementById("container_CUSTOM_APPROVAL_COMMENTS").innerHTML = "xhr: " + xhr.response + "  response: " + response.responseText + "  error: " + error.responseText + "  msg: " + msg;  }
 });
}

 

 

On the screen that needs to have the approval comments displayed, I added the following in the head section:

 

<SCRIPT type=text/javascript src="jquery-1.10.2.min.js"></SCRIPT>

 

I now realize as I write this post that adding this jquery file to the VSM installation folder was probably unecessary because an older version already exists.

 

I added the call to the function getApprovalComments to the onLoad property of the body tag on the screen.

 

Finally, where I want the approval comments to show up, I added "id=container_CUSTOM_APPROVAL_COMMENTS" to an opening table cell tag.

 

I am not 100% sure yet if this will display multiple comments or not and I still need to figure out what to do about comments that are extremely long. Hopefully this will help others who want to do something similar in their environment.

 

Thank you Gytis for steering me in this direction. I have never done anything with AJAX before and I am terrible with javascript so it was quite the learning experience.


Viewing all articles
Browse latest Browse all 150956

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>