The CreatorCon Call for Content is officially open! Get started here.

Create custom HTML field and populate with data from another table

BiancaK
Tera Expert

Good day SN Community

 

Wondering if anyone could assist in achieving the below please?

 

I have created a custom HTML field on the project form (SPM) 

 

I would like to populate this HTML field with a table and rows, reflecting the resource data from the demand record

BiancaK_0-1742143172151.png

 

Thanks

Bianca

 

#spm

#strategic portfolio management

5 REPLIES 5

BiancaK
Tera Expert

Thanks - this is how I have achieved it already 

 

Client script

BiancaK_0-1742194650226.png

 

function onLoad() {
 
  var ga = new GlideAjax('getResourceData');
        ga.addParam('sysparm_name', 'getResourceDetails');
        ga.addParam('sysparm_task', g_form.getUniqueValue());
       

        ga.getXML(getResourceData);
       
        function getResourceData(response){
            var answer = response.responseXML.documentElement.getAttribute("answer");
            g_form.setValue('u_planning_resources', answer);            
        }
   
}
 
Script include
BiancaK_1-1742194698822.png
var getResourceData = Class.create();
getResourceData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getResourceDetails: function(){
    var tsk;
    var dd = new GlideRecord('dmn_demand');
    dd.addQuery('project', this.getParameter('sysparm_task'));
    dd.query();
    if (dd.next()) {
        tsk = dd.sys_id;
    }
   
        var rd_tb = '<table style="width:100%" border="1px" cellspacing="1"><tr><th style="width:33%">Resource name</th><th style="width:33%">Start date</th><th style="width:34%">End date</th></tr>';
        var gr = new GlideRecord('resource_plan');
        gr.addQuery('task', tsk);
        gr.addQuery('active', true);
        gr.addNotNullQuery('user_resource');
        gr.query();
        while(gr.next()){
            rd_tb += '<tr><td>' + gr.user_resource.name + '</td>';
            rd_tb += '<td>' + gr.start_date + '</td>';  
            rd_tb += '<td>' + gr.end_date + '</td></tr>';  
        }
        rd_tb += '</table>';
        return rd_tb;
    },
    type: 'getResourceData'
});