Important Update: Community URLs redirect issues are partially resolved. Learn More. .
2018-10-19 07:57 AM
Hi, archeriers
I have build a Custom object to hide copy button. When the user belongs to a group and there is a specific value in a list of values, hide the copy button. This is the code:
<script type="text/javascript"></script>
<script>
Sys.Application.add_load(function() {
var currentUserID = parent.parent.ArcherApp.globals.userId;
var value2 = ArcherTech.UI.GenericContent.GetInstance().getFieldValue(19960);
var value = value2[0];
console.log(value);
var contenturl = 'https://10.17.11.18/api/core/system/group/user/' + currentUserID;
$.ajax({
type: "GET",
url: contenturl,
contentType: "application/json",
headers: {
'Content-Type': "application/json",
'Accept': "application/json"
},
success: function (result) {
console.log(result[0].RequestedObject.Name);
console.log(result[1].RequestedObject.Name);
if (result[1].RequestedObject.Name == "Usuarios" && value == "386278:0") {
$(document).ready(function () {
if($('#master_btnCopy')){
$('#master_btnCopy').hide();
}
});
}
},
error: function (err) {
console.log(err);
}
});
});
</script>
Works fine in edit mode but in view mode return this error:
var value2 = ArcherTech.UI.GenericContent.GetInstance().getFieldValue(19960);
var value = value2[0];
Unable to get property '0' of undefined or null reference
Thanks in advance
2018-10-19 08:44 AM
Elias the getFieldValues() only works in Edit mode. You'd have to inspect the element and get the text. Which will make it a little difficult being user Id is a little bit of a PITA to extract; it's found in the URL of the href attribute of the element.
Advisory Consultant
2018-10-19 09:50 AM
$CM.getFieldById(fid);
Will not work either?
Or David wrote pretty good codes here already:
https://community.rsa.com/message/916603?commentID=916603#comment-916603
2018-10-19 09:53 AM
$CM.getFieldValue() is just shorthand for ArcherTech.UI.GenericContent.GetInstance().getFieldValue()
Advisory Consultant
2018-10-19 09:56 AM
Yep, but I though it would work in either mode. Interesting.
But this should
ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(fldId);
work, right?
2018-10-19 09:58 AM
Yes, that should work in either mode, but getting the value of a field is different in Edit mode than it is in View mode.
Advisory Consultant
2018-10-19 10:01 AM
Yep. Like David suggested, you need to get over element ID by inspecting in Dev Tools. Link I provided contains the code also to do so, Elias.
2018-10-22 05:58 AM
Hi, i have tested David´s code but i have this error:
Debugger
2018-10-22 05:59 AM
David said, it will work in Edit mode, not in View.
Try this function: But you may need to change input to something else based on your element.
function getValue(fldId) {
var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(fldId);
var RPFieldRootId = RPFieldRoot.clientId;
return $('input[id*="'+ RPFieldRootId +'"]').val();
}
2018-10-22 08:24 AM
Hi Ilya i have tested the code and this is the values:
RPFieldRootId = master_DefaultContent_rts_s3799_f19960c
$('input[id*="'+ RPFieldRootId +'"]').val() = Undefined