I have a getSublistValue() call getting a percenta...
# suitescript
a
I have a getSublistValue() call getting a percentage column from a sublist on a suitelet. When the percentage is something with a decimal like 2.4%, the value from the getSublistValue() returns only the first two decimals, like .02 instead of .024. Is there anyway to get around this ?
b
where are you getting the value
and what code are you using to get it
a
the code is serverRequest.getSublistValue({}) and the field its getting is a % field. When the value is something like 4.5 or 3.25%, then it only takes seems like it cuts it off at the percent fractions. The result of the function is .03 or .04 instead of .0325 or .045
I'm wondering if I can make it work by changing the field to be text and then pull text ...
b
you have some weirdness going on
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 */
define(["N/ui/serverWidget"], function(serverWidget) {
  function onRequest(context) {
    log.debug("context", context);
    log.debug(
      "value",
      context.request.getSublistValue({
        group: "sublist",
        name: "fieldid",
        line: 0
      })
    );
    var form = serverWidget.createForm({
      title: "Simple Form"
    });
    var sublist = form.addSublist({
      id: "sublist",
      type: serverWidget.SublistType.INLINEEDITOR,
      label: "Inline Editor Sublist"
    });
    sublist.addField({
      id: "fieldid",
      type: serverWidget.FieldType.PERCENT,
      label: "Percent"
    });
    form.addSubmitButton({
      label: "Submit Button"
    });
    context.response.writePage({ pageObject: form });
  }
  return {
    onRequest: onRequest
  };
});
super basic suitelet logs percentages you enter in the first row as you would expect
a
/**
*@NApiVersion 2.x *@NScriptType Suitelet */ define(["N/ui/serverWidget"], function(serverWidget) { function onRequest(context) { log.debug("context", context); var router = {}; router[http.Method.GET] = handleGet; router[http.Method.POST] = handlePost; router[context.request.method] ? router[context.request.method] : handleError(context); } function handlePost(context){ var serverRequest = context.request; log.debug("value",serverRequest.getSublistValue({ group: "sublist", name: "custpage_percfieldid", line: 0 }) ); } function handleGet(context){ var form = serverWidget.createForm({ title: "Simple Form" }); var sublist = form.addSublist({ id: "sublist", type: serverWidget.SublistType.INLINEEDITOR, label: "Inline Editor Sublist" }); sublist.addField({ id: "custpage_percfieldid", type: serverWidget.FieldType.PERCENT, label: "Percent" }); form.addSubmitButton({ label: "Submit Button" }); context.response.writePage({ pageObject: form }); } function handleError(context){ //do stuff here } return { onRequest: onRequest }; });
when I do something closer to that, the % column returns a decimal cut at the hundredths. I have tried doing exactly that with the log and that is what was returned
b
dunno what to tell you, works fine for me after fixing the script to work
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 */
define(["N/ui/serverWidget", "N/http"], function(serverWidget, http) {
  function onRequest(context) {
    log.debug("context", context);
	var router = {};
	router[http.Method.GET] = handleGet;
	router[<http://http.Method.POST|http.Method.POST>] = handlePost;
	router[context.request.method] ?
		router[context.request.method](context) :
		handleError(context);
  }
  function handlePost(context){
	  var serverRequest = context.request;
	  log.debug("value",serverRequest.getSublistValue({
			group: "sublist",
			name: "custpage_percfieldid",
			line: 0
		  })
		);
  }
  function handleGet(context){
	var form = serverWidget.createForm({
      title: "Simple Form"
    });
    var sublist = form.addSublist({
      id: "sublist",
      type: serverWidget.SublistType.INLINEEDITOR,
      label: "Inline Editor Sublist"
    });
    sublist.addField({
      id: "custpage_percfieldid",
      type: serverWidget.FieldType.PERCENT,
      label: "Percent"
    });
    form.addSubmitButton({
      label: "Submit Button"
    });
    context.response.writePage({ pageObject: form });
  }
  function handleError(context){
	  //do stuff here
  }
  return {
    onRequest: onRequest
  };
});