Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom object works fine in edit mode but not in view mode (Hide Copy Button)

EliasTabarez1
Collaborator II

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

10 REPLIES 10

DavidPetty
Archer Employee
Archer Employee

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

$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 

$CM.getFieldValue() is just shorthand for ArcherTech.UI.GenericContent.GetInstance().getFieldValue()

 Advisory Consultant

Yep, but I though it would work in either mode. Interesting. 

 

But this should

ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(fldId);  

work, right?

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

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.

Hi, i have tested David´s code but i have this error:

 

Debugger 

$CM_getFieldValue' is undefined

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();
}

Hi Ilya i have tested the code and this is the values:

 

RPFieldRootId = master_DefaultContent_rts_s3799_f19960c

$('input[id*="'+ RPFieldRootId +'"]').val() = Undefined