Select reference field and copy record

user_ms
Tera Expert

I want to copy the value when selecting data from a reference item.

 

conditions
・When reference type item C (colmun_c) of table B (tb_b) is selected, copy the value from table A (tb_a) to table B (tb_b).

 

I can't do the following.
1. Copy from integer item (num_a) in table A to string item (str_b) in table B
2. Copy from string item (str_a) in table A to choise item (cho_b) in table B
*'str_a' is a string, but the value is a number. 

 

I use 'script incrudes' and 'client script'.

 

If anyone knows please let me know.

 

client script

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

    var ga = new GlideAjax('xxxxx_test.copy');
    ga.addParam('sysparm_name', 'getData');
    ga.addParam('sysparm_sysid', newValue);
    ga.getXMLAnswer(function(response) {
        var data = JSON.parse(response);
        if (data) {
            g_form.setValue("str_b", data.str_b);
            g_form.setValue("cho_b", data.cho_b);
         }
    });
	
}

 

 

script incrudes

 

var copy = Class.create();
copy.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getData: function() {
        var sysid = this.getParameter('sysparm_sysid');
        var gr = new GlideRecord('tb_a');
        if (gr.get(sysid)) {
            return this.getRecord(gr);
        }
        return {};
    },

    getRecord: function(record) {
        var data = {
			'str_b': record.num_a.toString(),
			'cho_b': record.str_a.toString(),
        };
        return JSON.stringify(data);
    },
	
    type: 'copy'
});

 

 

0 REPLIES 0