Ashraf
Ashraf

Reputation: 135

Url Parameter Error in Google Appscript with ContentService, MimeType XML

I am getting some issue when taking value form parameter here is my simple code in Google App script and deployed service. what is the issue ?

function doGet(e) {
  var num = e.parameter.num;
  var result=false;
  result=(num%2==0);
  if(result){
     return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.XML);
    }else{
     return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.XML);
  }

 }

https://script.google.com/macros/s/AKfycbz86LRyPqowhg_ajj48oM13aESMPms30tbne-_p9sWwJVcaQzg/exec?num=20

Here is google appscript deployed url

This error I am getting when I am hitting this url enter image description here

and code running error in App-script Environment enter image description here

Upvotes: 2

Views: 497

Answers (1)

Serge insas
Serge insas

Reputation: 46822

it seems that the issue might come from the modulo operation you are trying to apply to a string value, when I try this code it runs without error

function doGet(e) {
  var num = Number(e.parameter.num);// make it a number before testing parity
  var result=false;
  result=(num%2==0);
  var xmlContent = '<mydata>' + result+ num + '</mydata>';// added num value for test purpose
  if(result){
    return ContentService.createTextOutput(xmlContent).setMimeType(ContentService.MimeType.XML);
  }else{
    return ContentService.createTextOutput(xmlContent).setMimeType(ContentService.MimeType.XML);
  } 
}

That said, I suppose this is just a test code because I don't really see what it can be used for and the xml output is not valid but I'll leave you with that issue.

enter image description here

Upvotes: 1

Related Questions