Set autoValue of field to anther profiles usersId

I’m new to Meteor and programming, if this doesn’t make sense or you need more info please let me know.

I’m loading a profile page of another user. So I have 2 userIds; this.userId and the other users Id. I want to use autoValue to save both userIds when an action is taken. I can’t figure out how to set the other users id even though I can display it on the html page.

Path: schema.js

Schemas.class = new SimpleSchema({
    Title: {
        type: String,
        optional: true
    },
    loggedInUserId: {
        type: String,
        optional: true,
        autoValue: function() {
            return this.userId
        },
        autoform: {
            type: "hidden"
        }
    },
    otherUserProfileId: {
        type: String,
        optional: true,
        autoValue: function() {
           ***Not sure what to do here***
        },
        autoform: {
            type: "hidden"
        }  
    }
});

The pattern to add the logged in user’s id through autoValue is only possible because Meteor tracks the logged in user automatically, on both the client and server, so it’s available to the schema at invocation. You need to attach the id of the other user before you insert the document.

Thanks for that #ergusto. That sort of makes sense to me. Would you mind showing me how to do it in the example below. I’ve been trying to figure to use defualtValue to grab the helper but that isn’t working either.

Path: schema.js

Schemas.class = new SimpleSchema({
    Title: {
        type: String,
        optional: true
    },
    teacherProfile: {
        type: String,
        optional: true,
        autoValue: function() {
            return this.userId
        },
        autoform: {
            type: "hidden"
        }
    },
    studentProfileId: {
        type: String,
        optional: true,
        type: String,
         autoform: {
         defaultValue: "studentProfileId",
         type: "hidden"
    }
    }
});

Path: profile.js

Template.teacherProfile.helpers({
studentProfile: ()=> { 
var id = FlowRouter.getParam('id');

return Meteor.users.findOne({_id: id}); 
}
});

You can’t use defaultValue or autoValue in that way. Template helpers can only be called from the template. You need to set that field when you actually create the object.

const attrs = {
    studentProfileId: 'some id value',
}

Collection.insert(attrs);

This is my solution it seems to work. Thanks to everyone that helped.

Path: schema.js

Schemas.class = new SimpleSchema({
	Title: {
		type: String,
		optional: true
	},
	teacherProfile: {
		type: String,
		optional: true,
		autoValue: function() {
			return this.userId
		},
		autoform: {
			type: "hidden"
		}
	},
	studentProfileId: {
		type: String,
		optional: true,
		autoform: {
			type: "hidden"
		}
	}
});

Path: profile.js

Template.profile.helpers({
    studentProfile: ()=> { 
    	var id = FlowRouter.getParam('id');
    
    	return Meteor.users.findOne({_id: id}); 
    },
    studentProfileId: () => {
    	return FlowRouter.getParam('id');
    }
)};

Path: profile.html

<template name="profile">

	{{#autoForm collection="Jobs" id="Offer" type="insert"}}

		{{> afQuickField name='Title'}}			      
		{{> afQuickField name='studentUserId' value=studentProfileId}}		      	

		<button type="submit" class="btn btn-primary">Insert</button>

	{{/autoForm}}

</template>