question

johnjohn-0472 avatar image
0 Votes"
johnjohn-0472 asked AmosWu-MSFT commented

Inside my Remote Event Receiver the Current value and the After value for a Rich Text Editor field will be different even if i do not modify the field

I have the following Rich Text Editor field inside my sharepoint online with internal name = "ApproverFeedbackandnotesPowerBi":-

77591-j1.png




and inside my remove event receiver i am checking the Current Value of this field against the After value as follow:-

  public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
         {
             SPRemoteEventResult result = new SPRemoteEventResult();
             using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
             {
                 try
                 {
                     if (clientContext != null)
                     {
                           
                         ListItem currentItem = clientContext.Web.GetList(clientContext.Web.ServerRelativeUrl + "/lists/ApprovalProcess").GetItemById(properties.ItemEventProperties.ListItemId);
                         clientContext.Load(currentItem);
                         clientContext.ExecuteQuery();
                            
    
                         if (properties.ItemEventProperties.AfterProperties["ApproverFeedbackandnotesPowerBi"].ToString() != (currentItem["ApproverFeedbackandnotesPowerBi"] == null ? null : ToString())
                             )
                         {
    
                         }
                     }

now the check will always fails, so when i debug my code i have noted that the currentItem["ApproverFeedbackandnotesPowerBi"] will always have extra html tag (`<div class="ExternalClassD7C94EE0628F493686BC675B96532912">`), for example, in one case the currentItem["ApproverFeedbackandnotesPowerBi"] =

 <div class="ExternalClassD7C94EE0628F493686BC675B96532912">&#128993;Abstain By&#58;- . Comment&#58;-  Nothing was attached..<br>✅Approved By&#58;- . Comment&#58;-...<br><br></div>


while the properties.ItemEventProperties.AfterProperties["ApproverFeedbackandnotesPowerBi"] =

 &#128993;Abstain By&#58;- . Comment&#58;-  Nothing was attached..<br>✅Approved By&#58;-. Comment&#58;-...<br><br>




so can anyone advice why this is happening? and how i can fix it, so my comparison will work correctly?

office-sharepoint-online
j1.png (30.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AmosWu-MSFT avatar image
0 Votes"
AmosWu-MSFT answered AmosWu-MSFT commented

You can try to clear the HTML tags in these string values.

 public static string StripHTML(string input)
 {
    return Regex.Replace(input, "<.*?>", String.Empty);
 }

References:How do I remove all HTML tags from a string without knowing which tags are in it?


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@AmosWu-MSFT i thought of this approach, but i am afraid that it might fail on certain scenarios .. so my question is why this is happening at first place and is there a way to avoid it, rather than writing code to force the match between the current and the After properties?

0 Votes 0 ·

So far, I have not found other methods.
Of course, we can read column into text, but only translating <br> into /n, and it cannot achieve the same effect as AfterProperties.


0 Votes 0 ·

I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.
You can accept the helpful post as answer to help other community members find helpful information quickly.
You can also share your own solution here and accept it as answer, and we can learn from each other.

0 Votes 0 ·