SuiteScript 2.x entry point scripts must implement one script type function

I added a field in the Sales Order named Membership that will source from the customer record. Then when that field is set to the membership level (ex. elite member) it automatically set the discount item field to a specific discount item…. I encountered a notif saying SuiteScript 2.x entry point scripts must implement one script type function how do I fix this?

/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define([“N/currentRecord”, “N/runtime”], function(currentRecord,runtime) {

function pageInit(context) {

 const record = currentRecord.get()  // Get value of Membership Field   
 const user = runtime.getCurrentUser().name
}

var membership = currentRecord.getField({
    fieldId : "custentity1",
})

if(membership == "Elite"){
    //Setting up discount
    record.setValue({
        fieldId: "discountitem", //fieldId of the Discount Item 
        value: 137 // Internal ID of the Discount Item
    })}

    else {
        record.setValue({
            fieldId: "discount item",
            value: 0
        });
    }

    return {
        pageInit : pageInit
    }

});

retrieve multiple html values in javascript

On my node.js backend, I have this:

  {
    DATE: '2021-12-11 02:17:59.317432',
    LOCATION: 'Location',
    ASSIGNED_TRAINER: '[email protected]',
    CLIENT_USERNAME: 'Test User Name'
  },
  {
    DATE: '2022-01-04 02:27:11.278146',
    LOCATION: 'Location',
    ASSIGNED_TRAINER: '[email protected]',
    CLIENT_USERNAME: 'Test User Name'
  },
  {
    DATE: '2021-12-15 10:30:00.000000',
    LOCATION: 'Location',
    ASSIGNED_TRAINER: '[email protected]',
    CLIENT_USERNAME: 'Test User Name'
  }

and on the front-end, I am trying to grab the DATE field. and so what I do is this:

 <% if (data.length) {
    for(var i = 0; i < data.length; i++) { %>
      <input type="text" name="passedDates" id="passedDates" value="<%= data[i].DATE %>">
      <%  }
    } else { %>
   <% } %>

and then in my <script> tag, what I do is:

  for ( var z = 1; z <= lastDayOfM; z++ ) {
    
    const yourDate = new Date()
    var theDate = yourDate.toISOString().split('T')[0]

*here I am trying to get the values that I pass through the id ‘passedDates’

    var passedDates = document.getElementById("passedDates").value

    var finalDate = passedDates.split('-');

    var yyyy = finalDate[0];
    var mm = finalDate[1];
    var dd = finalDate[2];
    var theFinalDay = dd.split(' ')

but then I log yyyy, mm, dd, and then theFinalDay[0]. But it doesn’t store ALL of the date values in there. I need all of them in there, because then when going below:

    // check if todays date
    if ( z == today.getDate() && y == today.getFullYear() && m == today.getMonth() ) {
      var myTestPassedDate = theFinalDay[0]
      if (myTestPassedDate) {

*here i try to insert something into HTML, but it won’t do all 3 because it only stores one.

 day.innerHTML = myTestPassedDate + "<br><img src='https://miro.medium.com/max/512/1*nZ9VwHTLxAfNCuCjYAkajg.png' style='height: 10px; width: 10px;'>"
 

 }
      day.classList.add("today");
    }

    

how do I fix what I am trying to do? sorry if it is confusing, feel free to ask questions.

Creating 2D Array from an Array sorted by Atrribute | JavaScript

Hi i have this example:

let list = [{dog,1}, {dog,2}, {cat,1}, {cat,3}]

And i want this result:

let result= [
[{dog,1}, {cat,1}],
[{dog,2}],
[{cat,3}]]

I could do this with two different for-loops: first sorting by number, then creating a new array if the number changes in the second for-loop.
But i guess there will be a better solution but i’m not really familiar with JavaScript.

Maybe like .map() or .filter()?

How to open an “about:foo” URL, without being redirected to “about:blank#blocked”

I just want to set someones chrome home page to about:quit, so chrome always gets closed, once started. I tried to do that, but it didn’t even work to set this as home page.

So i tried, to set the URL to a data:text/html site, where you are redirected to about:quit per a javascript function, which gets called onload.
Doesn’t work either, because chrome just blocks redirecting to an about:foo URL.
How do I avoid that?

Catch block not executed when error is thrown from Try block within setTimeOut In Javascript

[![enter image description here][1]][1]I am trying to throw an exception from setTimeout within the try block.
See Below Code

    let a = 2 + 2;
    if (a == 4) {
        setTimeout(() => {
            console.log('Set time out')
            throw new Error()
        }, 3000)
    }
    else {
        console.log('Not 4')
    }

} catch (error) {
    console.log('catch block')
    console.log(error)
}```

But the control cannot come to the catch block and I am unable to see the result from console.log('catch block').


  [1]: https://i.stack.imgur.com/3DdhB.png

Cannot find name ‘BarcodeDetector’

I’m trying to create a new BarcodeDetector class as the example shows on MDN but I’m getting the above error.

let barcodeDetector = new BarcodeDetector({ formats: ['qr_code'] });

here is a link to a Stackblitz showing the error using angular 12.

any idea why?

How to arrage the data as rows and columns?

I have used my map function to iterative over the data and print it out. But I was unable to separate it as rows and columns.
There should be 5 columns that are fixed and the rows change dynamically, that is the reason I cannot use array indexing.

I am attaching reproducable code – Link

let array = [
    [
        72.3474349975586,
        83.77342224121094,
        83.77342224121094,
        72.3474349975586,
        97.0778579711914
    ],
    [
        80.1422348022461,
        93.16133117675781,
        93.16133117675781,
        80.1422348022461,
        108.54068756103516
    ],
    [
        108.37809753417969,
        125.22685241699219,
        125.22685241699219,
        108.37809753417969,
        147.92010498046875
    ],
    [
        163.5850372314453,
        197.7432098388672,
        197.7432098388672,
        163.5850372314453,
        228.80577087402344
    ],
    [
        198.08128356933594,
        236.1764678955078,
        236.1764678955078,
        198.08128356933594,
        276.9237060546875
    ],
    [
        126.81776428222656,
        147.2906951904297,
        147.2906951904297,
        126.81776428222656,
        174.1883544921875
    ],
    [
        95.24028778076172,
        110.93660736083984,
        110.93660736083984,
        95.24028778076172,
        129.43946838378906
    ],
    [
        95.24028015136719,
        110.93661499023438,
        110.93661499023438,
        95.24028015136719,
        129.43946838378906
    ],
    [
        126.8177719116211,
        147.2906951904297,
        147.2906951904297,
        126.8177719116211,
        174.1883544921875
    ],
    [
        198.081298828125,
        236.176513671875,
        236.176513671875,
        198.081298828125,
        276.9237060546875
    ],
    [
        163.5850372314453,
        197.74327087402344,
        197.74327087402344,
        163.5850372314453,
        228.80577087402344
    ],
    [
        108.37812042236328,
        125.22686767578125,
        125.22686767578125,
        108.37812042236328,
        147.92013549804688
    ],
    [
        80.1422348022461,
        93.16131591796875,
        93.16131591796875,
        80.1422348022461,
        108.54067993164062
    ],
    [
        72.347412109375,
        83.77342987060547,
        83.77342987060547,
        72.347412109375,
        97.07785034179688
    ],
    [
        80.1422348022461,
        93.16131591796875,
        93.16131591796875,
        80.1422348022461,
        108.54067993164062
    ],
    [
        108.37812042236328,
        125.22686767578125,
        125.22686767578125,
        108.37812042236328,
        147.92013549804688
    ],
    [
        108.37809753417969,
        125.22685241699219,
        125.22685241699219,
        108.37809753417969,
        147.92010498046875
    ],
    [
        80.1422348022461,
        93.16133117675781,
        93.16133117675781,
        80.1422348022461,
        108.54068756103516
    ]
]

var num = array.map(function(subarray){
  return subarray
  })


for(i=0;i<num.length;i++){
  for(j=0;j<5;j++){
    console.log(num[i][j])
  }
}

The output I am getting is shown in the figure

enter image description here

But I need something like this, but with 5 columns and rows changing dynamically based on the RestApi.

enter image description here

[Note: the values in the image and code may change as they are kept for reference. I am getting values from RestApi so they keep on changing.

Call object function in RequireJS

I use RequireJS to load some scripts.

Now I would like to create some own methods which also needs the loaded script. I’ve tried a lot but I always get Uncaught (in promise) ReferenceError: hd is not defined

Calling the method ‘connect’:

hd.connect.call(token);

JS

...
require.config({

shim: {
    'socket.io': {
      exports: 'io'
    },
    'socket.io-stream': {
      exports: 'ss'
    }
  },
  paths: {
    'socket.io': WEBSOCKET_PROXY_HOST + '/socket.io/socket.io',
    'socket.io-stream': WEBSOCKET_PROXY_HOST + '/socket.io-stream/socket.io-stream'
  },
  waitSeconds: 1

});

requirejs([
  'socket.io', 'socket.io-stream'
], function(io, ss) {

  // Setup Methods & Events

  const hd = {

    connect : function(token) {
      // Connect to Socket, Proxy Server & authenticate
      socket = io(WEBSOCKET_PROXY_HOST, {
        auth: {
          token: token
        }
      }).on('connect', function(data) {
        socketConnected = true;
        isStreaming = false;
        console.log('connected to socket');
        if (activeRecording) {
          //#startRecording();
        }
      });
...

How do I change the location of the pushed array items by clicking on a day item with Vue3?

Here’s my calendar row with day items in it:

enter image description here

The problem is…

…when I select another day, let’s say 13th of Monday, and after that try to add new tasks they still push to the task array of the first day.

Let me just show you:

enter image description here
On the Image above I switch to Monday, and the task list is empty as it should be by default, looks pretty good to me….but…

enter image description here

After I try to add new tasks, it didn’t add any to the selected day, but just pushed them into the first one (I added two more, there were 3 on the first screen)

Let me show you the code:

This is my main component in which all other’s are used in:
Main.vue

setup() {
    // Create days:
    const currDay = ref({});
    const dayArr = ref([]);

    // Just a library for working with dates:
    const moment = require("moment");
    const daysRemainingThisMonth = moment()
      .endOf("month")
      .diff(moment(), "days");
    /*=============================================
        =            Firebase            =
    =============================================*/
    const { user } = useAuthState();
    const auth = getAuth();

    const router = useRouter();
    const signOutUser = async () => {
      try {
        await signOut(auth);
        router.push("/auth");
      } catch (e) {
        alert(e.message);
      }
    };
    /*=====  End of Firebase  ======*/
    const store = useStore();

// Generate the day data:
    const fillDayArray = () => {
      dayArr.value = Array(daysRemainingThisMonth)
        .fill("")
        .map((item, index) => {
          return {
            currDay: moment().add(index, "day").format("D"),
            dayOfWeek: moment().add(index, "day").format("dddd"),
            tasks: [ ],
            id: Math.floor(Math.random() * new Date()),
          };
        });
      currDay.value = dayArr.value[0];
    };

    const updateCurrDay = (value) => {
      currDay.value = value;
    };

    onMounted(() => {
      fillDayArray();
    });

Template of Main.vue:

<template>
  <div id="main">
    <!-- ! Top Level: -->
    <div class="auth"></div>

    <div class="greeting-block">
      <button @click="signOutUser">Sign Out</button>
      <h1 id="greet-user">{{ user?.email }}</h1>
    </div>

    <div class="header-container">
      <Header />
      <Menu />
    </div>

    <div class="calendar-display">
      <Calendar 
          :dayArr="dayArr"
          @updateCurrDay="updateCurrDay"
      /> 
    </div>

    <div class="task-list">
      <TaskView 
          v-if="dayArr.length"
          :dayArr="dayArr"
          :currDay="currDay" 
      />
    </div>
  </div>
</template>

Component where the tasks are rendered: TaskView.vue

 props: {
    dayArr: {
      type: Array,
      default: () => [],
    },
    currDay: {
      type: Object,
      default: () => ({}),
    },
  },
  setup(props) {
    const store = useStore();

    const dayArrData = ref(props.dayArr);
    const currDay = ref(props.currDay);

    const getClickedTask = (item) => {
      store.state.clickedTask = item;

      store.state.cardStatus
        ? (store.state.cardStatus = false)
        : (store.state.cardStatus = true);
    };
    // ! Delete Item:
    const deleteItem = (idx) => {
      currDay.value.tasks.splice(idx, 1);
    };

   // ====== How do I tell it to push items to the currDay? ======
    const addItem = () => {
      currDay.value.tasks.push({
        name: "Empty Task" + Math.random().toString().substring(0, 4),
        description: "No description...",
      });
 
    };


    console.log(currDay.value);
    onMounted(() => {});
    

    return {
      getClickedTask,
      deleteItem,
      addItem,
      dayArrData,
    };
  },

Template of TaskView.vue:

<template>
  <div>Active card: {{ currDay }}</div>
  <hr />
  <div>Current Task is: {{ currDay.dayOfWeek }}</div>
  <div class="task-wrapper">
    <p id="task-counter">Tasks Today: {{ currDay.tasks.length }}</p>
    <div class="task-counter-wrapper">
      <!-- ? Render if there are no tasks available: -->
      <div class="empty-msg" v-if="currDay.tasks.length == 0">
        <p>Start by adding a New Task!</p>
      </div>

      <div class="task-list" v-for="(task, idx) in currDay.tasks" :key="idx">
        <div class="list-item">
          <div class="container">
            <input class="list-checkbox" type="checkbox" />
              {{ task.name }}
          </div>

          <div class="item-actions">
            <button class="edit-item btn" @click="getClickedTask(task)">
              <img class="icon" src="./Images/editing.png" />
            </button>

            <button class="delete-item btn" @click="deleteItem(idx)">
              <img class="icon" src="./Images/delete.png" />
            </button>
          </div>
        </div>
      </div>
    </div>

    <div class="item-card">
      <ItemCard />
    </div>

    <div class="add-task-wrapper">
      <button id="add-task-btn" @click="addItem()">+ Add a new task</button>
    </div>
  </div>
</template>

accessing passed data on front end

I have this on the node.js backend:

var getschedule = "select * from SCHEDULE"
console.log(getschedule);
ibmdb.open(ibmdbconn, function(err, conn) {
    if (err) return console.log(err);
    conn.query(getschedule, function(err, rows) {
        if (err) {
            console.log(err);
        }

        console.log(rows)
        
        res.render("calendar.ejs", {data: rows, trainerFirstName: req.session.firstname, trainerLastName: req.session.lastname});

        conn.close(function() {
        });
    });
});

and as you can see I am passing data: rows. Now in my <script> on the front end, i want to access all the data inside data, which i am passing. how can i do this?

delete an object in an array based on index at level 1 and level 2

I have a array of object which has sub arrays, I want to delete the subarray object based on the index from both the levels.

For example if want to delete object with id:12 I should pass firstIndex = 0 and secondIndex = 1;
Pls note above mentioned eg: is for better understanding of question and not to delete element by id should be deleted based on index only(use case is different and index are received from different source).

const array = [
    {
        id: 1,
        row: [
            {id: 11, value: x},
            {id: 12, value: y},
            {id: 13, value: z},
        ],
    },
    {
        id: 2,
        row: [
            {id: 21, value: a},
            {id: 22, value: b},
            {id: 23, value: c},
        ],
    }
]

firstIndex = 1, secondIndex = 2

const result = [
    {
        id: 1,
        row: [
            {id: 11, value: x},
            {id: 12, value: y},
            {id: 13, value: z},
        ],
    },
    {
        id: 2,
        row: [
            {id: 21, value: a},
            {id: 22, value: b},
        ],
    }
]

firstIndex = 0, secondIndex = 1

const result = [
    {
        id: 1,
        row: [
            {id: 11, value: x},
            {id: 13, value: z},
        ],
    },
    {
        id: 2,
        row: [
            {id: 21, value: a},
            {id: 22, value: b},
            {id: 23, value: c},
        ],
    }
]

const result = array.map((el, i) => (i === firstIndex) && el.rows.map(elm, (elm, index) => (index === secondIndex ) && elm.splice(index, 1)))