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

cancel
Showing results for 
Search instead for 
Did you mean: 

Record Permission Custom Object

AkshayDaniel
Contributor III

We are working on a requirement wherein we have two manual record permission fields that get populated at different stages of a workflow, the idea is to not have the same person in both these record permission for which the following custom object was written

 

 

<script type="text/javascript">

var reviewerFieldId = 1234;
var peerreviewerFieldId = 5678;

Sys.Application.add_load(function() {

$('div[id*="f' + peerreviewerFieldId + 'cdp"]').change(function(){
var rev1 = $CM.getFieldValue(reviewerFieldId);
var rev2 = $CM.getFieldValue(peerreviewerFieldId);

if(rev1=rev2)
{
alert('Peer reviewer and Reviewer cannot be same person');
});
});

 

</script>

 

 

Alert is followed by clearing the name from second record permission field, however we are unable to trigger the .change event for this most probably it could be due not  have proper element selected. 

 

Kindly advise if record permission fields have different Jquery selector compared to other general fields.

 

We have tried the following selectors

1.$('div[id*="f' + peerreviewerFieldId + 'cdp"]')

2. $('input[id*="f' + peerreviewerFieldId + 'shf"]')

3.$('div[id*="f' + peerreviewerFieldId + 'c_s"]')

None of them worked

 

Archer version is 6.4 HF1.

21 REPLIES 21

Have not tried yet as did not have a need. But like David Pettysaid, some elements are not responding to change event.

In such a case, you can use:

1. Approach proposed by Jason Solar, setting up a constant loop checking the field with certain interval.

2. Maybe you can perform checks on keyup/down/mouseclicks events.

Ilya_Khen
Champion III

I had some time on Saturday to think a bit deeper into the case, and came up with one very nasty approach to resolve the main issue, but one should never use it for obvious reasons. Still, if you understand implications, you may use for your own risk and sake:

<script>
     Sys.Application.add_load(function() {         
          redefineStandardSetter($("#master_DefaultContent_rts_s566_f17143c_shf")[0], "value");
         
          $("#master_DefaultContent_rts_s566_f17143c_shf").change(function(){
               // Do perform here the onchange actions
          });
     });
    
     function redefineStandardSetter(obj, property) {
          Object.defineProperty(obj, property, {
               configurable: true,
               enumerable: true,

               set: function(value) {
                    this.setAttribute(property, value );
                    $("#master_DefaultContent_rts_s566_f17143c_shf").trigger('change');
               },
               get: function() {
                    return this.getAttribute(property);
               }
          });
     }
</script>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

1. Change input identifiers to your own.

2. I was lazy enough to not make function for retrieving the input identifiers for better coding, so excuse me for scrappy code.

3. I tried it on the ValuesPopup type of a RP fields. Dunno if it would work on the Dropdown, etc.

Interesting approach.

So, the change event actually triggered?

 

A side note, I did a google search on attaching an event handler to a hidden element, which is what our issue is here, in case that wasn't made clear.

 

Found an article  event handling - jQuery - Detect value change on hidden input field - Stack Overflow 

It means Mutation Observer (as did Ilya Khen some time ago ), but also mentions the IE limitation.  So, since most folks use IE, I'm guessing mutation observer won't work.

 

There's additional comments and a fiddler link there that someone offers as a way to add event handler to hidden item.

I can't confirm if this works, though and haven't tested.

I'm satisfied with my current solutions, at the moment, but thought I'd share.

Yep, change will be triggered as I override standard behaviour. It works in my environment, feel free to test in yours

Yeah, the Change event only pertains to input elements

 Advisory Consultant

I also did some digging and found the following on StackOverflow (code is from the link that Jason Solar‌ posted) and seems to work pretty well for users/group field set as values popup.

 

The IE issues is for IE 10 and lower.  If you're running the latest of Archer IE 10 isn't supported.

<script type="text/javascript">
     var fldId = 20725;
     MutationObserver = window.MutationObserver || window.WebKitMutationObserver;

     var trackChange = function(element) {
     var observer = new MutationObserver(function(mutations, observer) {
          if(mutations[0].attributeName == "value") {
          $(element).trigger("change");
          }
     });

     observer.observe(element, {
          attributes: true
     });
}

     Sys.Application.add_load(function() {
          trackChange( $('input[id$="f' + fldId + 'c_shf"]')[0] );
          $('input[id$="f' + fldId + 'c_shf"]').change(function(){
               console.log("User field changed");
          });
     });
</script>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 Advisory Consultant

Yeah, maybe I should have first looked into the stackoverflow rather than creating something with object setter  But I remember that me and Jason Solar, had some issues with Mutation Observer element.

I think I had problems with IE 11.  

Tested out Mutation Observer some time ago when you, Ilya, and I were discussing and it worked great in Chrome, but then tested in IE and no bueno.

I tested above in IE 11 (that comes with Windows 10) and had no issues.

 Advisory Consultant

Thanks David Petty‌ for the heads up.  I'll have to try my M.O. code again in IE and see if I still have issues.

Maybe I didn't code something correctly.