Solved

Sage CRM Custom Content Trouble

Posted on 2011-03-10
17
1,424 Views
Last Modified: 2012-08-13
Using the Custom Content when the page loads. This code will pop an alert, but it is showing that comp_info_upd_ox is null when it is not. I don't have any conditionals in here right now, because I'm just testing the code. Why would the value be null?

<script>

window.attachEvent ('onload', function () {
ShowMyAlert();
});

function ShowMyAlert()
{
var myDate = document.getElementById("comp_info_upd_ox";);

alert(myDate) // this displays "null" even when a date is present in the record??
}

</script>
null01.png
0
Comment
Question by:BowTech
  • 10
  • 7
17 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 35107405
This

var myDate = document.getElementById("comp_info_upd_ox";);

should be

var myDate = eWare.GetContextInfo("company", "comp_info_upd_ox");

0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 35107411
No that's a lie. GetContextInf won't run in client side...

var myDate = document.getElementById("comp_info_upd_ox");

0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 35107445
In fact the script is not quite right. See below.

Lee
<script language="Javascript">
  window.attachEvent ('onload', ShowAlert);

  function ShowMyAlert()
  {
    var myDate = document.getElementById('comp_info_upd_ox');
    alert(myDate); // this displays "null" even when a date is present in the record??
  }
</script>

Open in new window

0
 

Author Comment

by:BowTech
ID: 35109495
Thank you for the suggestions. Unfortunately, all three produce the same result: no alert appears at all. Also I noticed, the extra ";" after ("comp_info_upd_ox";)  in my first post does not actually appear in the code - it came in on the copy/paste.  The only code that produces the alert is that in the original post, but it isn't pulling the value.
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 35109906
I can see the fault.

This:

window.attachEvent ('onload', ShowAlert);

should be

window.attachEvent ('onload', ShowMyAlert);


Also, the fields in the page are not named the same way as the fields in CRM are named. Try doing:

document.getElementById('Datacomp_info_upd_ox');
0
 

Author Comment

by:BowTech
ID: 35111297
Ah, getting closer. Thanks so much!  The alert pops now, but still says "Null" on date-populated records.

Here is the latest CustomContent scripting:

<script language="Javascript">

window.attachEvent ('onload', ShowMyAlert);

function ShowMyAlert()
{
var myDate = document.getElementById('Datacomp_info_upd_ox');
    alert(myDate); // this displays "null" even when a date is present in the record??
  }
</script>
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 35117528
There's a couple of things to consider here.

Firstly do you want the alert to appear when the screen is in view mode or edit mode? If it is view mode then you need to grab the _Data field from the screen. In edit mode you don't prefix it with _Data.

This will pop an alert in both view and edit mode. It will only populate the alert when in view mode though. If you want both then you need to do something else to determine the mode. If you only want the alert in one mode and not the other you need to let me know.

<script language="javascript">
window.attachEvent('onload', ShowMyAlert);

function ShowMyAlert()
{
  var myDate = document.getElementById('_Datacomp_info_upd_ox').innerText;
  alert(myDate);
}
</script>
0
 

Author Comment

by:BowTech
ID: 35129223
Thank you - this is very, very close to doing exactly what we need!  Using the code above, it is popping in both view and edit mode. View mode will show the field contents, while edit (change) mode just shows the box with no information in it.

Just having the popup display in view mode when the Company entity record first appears is all I want.  Please let me know how to determine the mode.  Thanks again!
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 25

Expert Comment

by:Lee Savidge
ID: 35129573
Ok, you're relying on a few things here first. The main thing to realise is that for some dumb reason Sage don't provide a way to determine screen mode client side. You have to use some javascript hacks to do work it out. The way to do it is to check to see if the element doesn't exist, in this case it looks for the comp_name field in the document. If it doesn't find it, it will run the alert as you are in view mode. If it does find it the screen is in edit mode.

So, if you're putting this on the company summary screen (CompanyBoxLong), this will work fine. It will not work for example on the Opportunity summary screen as the field doesn't exist.

<script language="javascript">
window.attachEvent('onload', ShowMyAlert);

function ShowMyAlert()
{
  if(!document.getElementById("comp_name"))
  {
    var myDate = document.getElementById('_Datacomp_info_upd_ox').innerText;
    alert(myDate);
  }
}
</script>
0
 

Author Comment

by:BowTech
ID: 35131183
Ah, very interesting. I would guess Sage keeps a few secrets so we can pay for professional services.  The code is going on the Company Entry Screen, and it seems to work until I add a conditional checking if the myDate variable is populated. Now nothing displays. Sorry, I've never written client/server JavaScript before.

<script language="javascript">
window.attachEvent('onload', ShowMyAlert);

function ShowMyAlert()
{
  if(!document.getElementById("comp_name"))
  {
    var myDate = document.getElementById('_Datacomp_info_upd_ox').innerText;
    if(myDate == '' || myDate == 'undefined' || myDate == 'null' || myDate == null)
    {  // note - also tried if(!myDate)
        alert(myDate); // only want this to show if there is no date
    }
  }
}
</script>
0
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 500 total points
ID: 35136267
Check the field content length when the field is empty.

function ShowMyAlert()
{
  if(!document.getElementById("comp_name"))
  {
    var myDate = document.getElementById('_Datacomp_info_upd_ox').innerText;
    if(myDate.length > 1)
    {  // note - also tried if(!myDate)
        alert(myDate); // only want this to show if there is no date
    }
  }
}
</script>
0
 

Author Comment

by:BowTech
ID: 35138577
Ok, awesome. I had to flip it to myDate.length < 1, since we alert on no date. However, the script wouldn't catch <1, so I tried <6 and it works.  This is perfect. Thanks so much. I need to take this a step further now and check the date to see if more than six months have passed since the last date was entered.  I'll probably need some help on that, but I can open a new thread if you'd like to help and earn more points.
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 35138631
That would be a new question as dealing with date strings from Sage CRM in javascript and parsing them to do calculations is not quite so simple. Fiddly is a good word for it.

Lee
0
 

Author Closing Comment

by:BowTech
ID: 35139733
Very helpful. Thanks!
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 35140181
Anytime. There isn't much help out there for Sage CRM sadly so I do what I can.
0
 

Author Comment

by:BowTech
ID: 35140207
it.toolbox.com has a CRM group that helps out quite a bit.
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 35140236
I'll stick to here :) If you need more Sage CRM help, just post a question with "Sage CRM" written in it and my question filter will email me about it.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Salesforce.com is a cloud-based customer relationship management (CRM) system. In this article, you will learn how to add and map custom lead and contact fields to your Salesforce instance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now