SetFieldValue not changing the value of a Lookup

Posted by ByronB on 14-Feb-2015 05:50

Hi, I need to change the value of a lookup based on another fields value. The thing is we are using to hide the text box and selector etc to make the field "ReadOnly":

// Making the Account Manager field Read Only
var accmgrid = rbf_getFieldValue('accountManager');
$('#txtaccountManager').parent('td').hide();
$('#accountManager_' + accmgrid + ' span:nth-child(1) i:nth-child(1)').hide();

OnChange event:

<script>

function onChangeDivision(form)
{
var relDivision = form.contactDivision.value;
if (relDivision != ""){
function cb(values) {
var acctMgr = values[0][0];
//alert(acctMgr);
rbf_setFieldValue('accountManager', acctMgr);
}
rbf_selectQuery("select accountManager from division where id=" + relDivision, 1, cb);
}
}
</script>

Why wont the setfieldvalue set? What other way could i possibly achieve this? We do not want the users to set this value at all.

All Replies

Posted by ByronB on 16-Feb-2015 03:31

Even if I exclude the first code so its a normal lookup (nothing hidden) the value wont set?

Posted by ByronB on 16-Feb-2015 04:37

Hi, just to further. If I alert the previous value and the set values the correspond but not visually:

<script>

function onChangeDivision(form)

{

var relDivision = form.contactDivision.value;

if (relDivision != ""){

function cb(values) {

var acctMgr = values[0][0];

alert(acctMgr);

//$('#rbi_F_accountManager span').click();

//$('#rbi_F_accountManager').children().remove();

//rbf_setFieldValue('accountManager', null);

rbf_setFieldValue('accountManager', acctMgr);

alert(rbf_getFieldValue('accountManager'));

}

rbf_selectQuery("select accountManager from division where id=" + relDivision, 1, cb);

}

}

</script>

Posted by Gian Torralba on 16-Feb-2015 06:58

Hello,

This is a known issue. You can set the lookup value as you said by using the  rbf_setFieldValue method but will not display the link below the field. Here is a previous post you might want to look at https://community.progress.com/.../27430.aspx

Thank you,

Gian

Posted by ByronB on 17-Feb-2015 03:56

Hi Gian

Thanks for that, it got us close:

<script>

function onChangeDivision(form)

{

var relDivision = form.contactDivision.value;

if (relDivision != ""){

function cb(values) {

var acctMgr = values[0][0];

//alert(acctMgrName);

//alert('Before: ' + acctMgr);

//$('#rbi_F_accountManager span').click();

//$('#rbi_F_accountManager').children().remove();

//rbf_setFieldValue('accountManager', null);

rbf_setFieldValue('accountManager', acctMgr);

rbf_selectQuery("select id, name from USER where id=" + acctMgr, 1, function cback(val){

           var acctMgrId = val[0][0];

var acctMgrName = val[0][1];

alert(acctMgrName + " " + acctMgrId + "Old ID: " + {!accountManager#id});

rbf_selectObject(acctMgrId, acctMgrName, null, "accountManager", false);

//rbf_selectObject(acctMgrId, acctMgrName);

$('#accountManager_' + acctMgrId + ' span:nth-child(1) i:nth-child(1)').hide();

});

}

rbf_selectQuery("select accountManager from division where id=" + relDivision, 1, cb);

}

}

</script>

The display is good to go however on looking at the DOM the accountManager_(CurrId) is still the old Account Managers Id. As the code is above it doesnt work with the selectObject. if you change it to:

rbf_selectObject({!accountManager#Id}, acctMgrName, null, "accountManager", false);

It works but the accountManaget_(AcctMgrId) is the old value but not the new assigned Account Manager id

Posted by ByronB on 17-Feb-2015 04:05

The Id for the specific user should be 10844, i have used setFieldValue and selectObject after setting the value.

Am I missing something?

Posted by Gian Torralba on 17-Feb-2015 12:45

Hello Byron,

If you are using the selectObject function then you don't need to use the setFieldValue method. The selectObject function is used in the lookup selector popup. Can you check your parameters in the method?

Thank you,

Gian

Posted by ByronB on 17-Feb-2015 15:17

Thanks Gian

I have done what you suggested using:

<script>

function onChangeDivision(form)
{
	var relDivision = form.contactDivision.value;
	if (relDivision != ""){
		function cb(values) {
		var acctMgr = values[0][0];
		
		rbf_selectQuery("select id, name from USER where id=" + acctMgr, 1, function cback(val){
            var acctMgrId = val[0][0];
			var acctMgrName = val[0][1];
			rbf_selectObject(acctMgrId, acctMgrName, null, 'accountManager', false);
			$('#accountManager_' + acctMgrId + ' span:nth-child(1) i:nth-child(1)').hide();
		});

		}
		rbf_selectQuery("select accountManager from division where id=" + relDivision, 1, cb);
	}
}
</script>


Everything seems to be ok via the DOM but the old Account Manager is still being saved?

Posted by ByronB on 17-Feb-2015 15:24

Everything looks fine here but the old Account Manager is still being saved

Posted by Gian Torralba on 18-Feb-2015 14:16

Hello,

Can you try checking the syntax of the selectObj method in the popup box? try checking the record's link and see if it matches your parameters. I tried using that previously and I can set the correct id with it.

Thanks,
Gian

This thread is closed