Wednesday 16 November 2011

Give a bit of feedback

Ever had a InfoPath Form Services form with a simple Submit and Close mechanism but wanted to give the user that little bit more ? Wouldn’t be great if we could display a status message to the user ? Well you could create a separate form view to display a confirmation message or we could just display a SharePoint status message like the one below…

image

By using a custom link to launch the InfoPath form and including a query string within our source message we can trigger a status message within a content editor web part.

Just add a content editor web part to the page and add a little JavaScript magic:

   1:  <script type="text/javascript">
   2:   
   3:    var l = window.location.href;
   4:    l = l.replace('?','&');
   5:    var p = l.split('&');
   6:    
   7:    for(var i in p)
   8:      if (p[i].indexOf("status=") >= 0)
   9:      {
  10:        var values = p[i].split('=');      
  11:        var value = values[1];
  12:   
  13:        if (value=='ok')
  14:        {
  15:           ExecuteOrDelayUntilScriptLoaded(ShowStatusInfo, "sp.js");
  16:        }
  17:      }
  18:   
  19:     function ShowStatusInfo()
  20:     {
  21:        msg = SP.UI.Status.addStatus("Expense Form", "<img src='/_Layouts/Images/mewa_info.gif' align='absmiddle'> <font color='#AA0000'>Your expense claim was submitted successfully</font>", true);
  22:        SP.UI.Status.setStatusPriColor(msg, "yellow");
  23:     }
  24:   
  25:  </script>

 

 

Launch the page with a query string including &status=ok and hey presto you have a happy user.


Of course the close button will also display the same message but I leave that as an exercise for the reader…

No comments:

Post a Comment